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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recent content by CadGuyExtraordinaire

  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)...

Part and Inventory Search

Back
Top