Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. CadGuyExtraordinaire

    difference between system function and backticks

    There's also another way...if you want to watch/parse the output of the executed command as it's happening and not just wait for it to end to get all the output (like backticks) you can use open...you can get the exit status, the output, and even a sub-process pid...it's the only way to go for...
  2. CadGuyExtraordinaire

    sort a file by field

    Basically you put the data in hashes and assign a unique id to it so you can have multiple per user or subject then do the sort on that ...I'll show the by email below (note that if you're sorting on ascii then use "cmp" and if it's numeric like a length or whatever then use "<=>" hope this...
  3. CadGuyExtraordinaire

    Writing and modifying a file.

    In my experience it takes longer to do the tie/modify than to just read through the file writing to a new one then move the file : open(FILE,$file); open(OUT,">$file.out"); print OUT "prepend\n"; while(<FILE>) {print OUT} close(OUT); close(FILE); `mv $file.out $file`; UNLESS you are just...
  4. CadGuyExtraordinaire

    Howto: Use a variable as a file handle.

    Yeah, you can use the FileHandle seek and tell (which are actually just frontends to the regular seek and tell which would also work) : $fh= new FileHandle; $fh->seek(0,0); or just, seek($fh,0,0); also you can use the flock on the filehandle created by the FileHandle module...
  5. CadGuyExtraordinaire

    Howto: Use a variable as a file handle.

    NO, it works... I ran your code and found that you dont have $mode set to anything...and the "open" procedure wants 2 args, the filehandle and an expression...if it starts with ">" or ">>" it will write to the file (what you want..) Here is the code that works: use Fcntl qw(:flock)...
  6. CadGuyExtraordinaire

    How to use $variable

    no...that's not the problem because I even tried: BEGIN{$modulename = &quot;abc&quot;} use $modulename; which would do the variable assignment prior to the use since begins and uses are both at compile time and happen in order of appearance. The 'use' just cant take an expression. cge
  7. CadGuyExtraordinaire

    Simple Question On chop.

    booo! ;)
  8. CadGuyExtraordinaire

    anding 2 binary values

    um...cant you just go: $in_bin =&quot;001100110011&quot;; $main_bin=&quot;000000000001&quot;; $out = $in_bin & $main_bin; print &quot;out is $out\n&quot;; for example?
  9. CadGuyExtraordinaire

    Simple Question On chop.

    or: $blah=&quot;blah/blah/blah.bl&quot;; ($firstbit,$lastbit)=$blah=~/^(.*\/)([^\/]+$/; or if it's a file path... use File::Basename; $firstbit=dirname($blah); $lastbit=basename($blah); what's that expression about skinning cats?
  10. CadGuyExtraordinaire

    How to use $variable

    Well, it looks like use doesnt accept an expression...it is however equivalent to: BEGIN { $modulename=&quot;abc.pm&quot;; require $modulename; } and if you want to see the equivalent of use Module @list: BEGIN { $modulename=&quot;abc.pm&quot;; require $modulename; import...
  11. CadGuyExtraordinaire

    split an array

    &quot;odd line numbers content&quot; not the odd content...
  12. CadGuyExtraordinaire

    split an array

    Well, that would put the odd *values* into one array and the even *values* into the other...not the indicies... actually, looking closer at MakeItSo's code I see it's actually right..sorry about that!
  13. CadGuyExtraordinaire

    split an array

    I think dkin wants the values of the odd indexes in 1 and the even indexes in the other...not the odd values in one and even values in another... If you want odd/even indexes, do this: @list=qw(a b c d e f); for($i=0;$i<=$#list;$i++) { if ($i/2==int($i/2)) {push(@evens,$list[$i])}...
  14. CadGuyExtraordinaire

    unix command in perl

    Ok, that'll probably all work, but you can do the whole thing much easier and cleaner.. first off, it looks like you want the current date/time in the filename...do you want it to be the perl seconds format like you have as one big number or would you want the english readable way? here's a way...
  15. CadGuyExtraordinaire

    How to write each word in a text file on a new line

    you should really use the split(&quot; &quot;) because the /\s+/ will put any leading spaces on the line as an element of the list ... the &quot; &quot; understands tabs, spaces etc too and wont put the leading spaces as an element: $string = &quot; a b c&quot;; @list= split(/\s+/,$string)...
  16. CadGuyExtraordinaire

    combining regexps

    Also, why are you also backslashing the commas &quot;,&quot; in the substitution the [stuff in here] isnt comma separated, it's just a group of characters to match...I bet considering the fact rotis23 doesnt want to escape the periods that they are working on text stuff (like stuff people...
  17. CadGuyExtraordinaire

    Removing Blank Space In String

    yes, \s will also match tabs...I didnt think we were after blanklines too...well, we can just go: $text=&quot; sdf adsf ds s s sd sdf s df dafs &quot;; foreach $line (split(/\n/,$text)) { ($line)=$line=~/^\s*(.*?)\s*$/m; $line=~s/\s+/ /g; print &quot;new line : is...
  18. CadGuyExtraordinaire

    Reading in multiple files simultaneously

    Additionally if the files are like list of names and second file is like their addresses you can read them both into 2 lists and just use the same index to pull the two records... open(IN1,in1); open(IN2,in2); @IN1=<IN1>; @IN2=<IN2>; now you can do list things to match them up like $IN1[34]...
  19. CadGuyExtraordinaire

    Removing Blank Space In String

    Very true all...and just to hilight perl's great ability to solve the same problem in different ways...you can more simply go: ($text)=$text=~/^\s*(.*?)\s*$/; # trim head/tail at same time $text=~s/\s+/ /; # faster than using the [2,] notation.. # note in the first line the .*? will...
  20. CadGuyExtraordinaire

    How do I call external script and continue ignoring return

    Yeah, fork is the way to go...you should probably take care to watch the children after your loop to make sure they eventually finish and catch on the errors...also if you are doing any perl code in the child other than just exec a system script then just use this kind of form: if($ChildsPid =...

Part and Inventory Search

Back
Top