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...
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...
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...
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...
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)...
no...that's not the problem because I even tried:
BEGIN{$modulename = "abc"}
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
um...cant you just go:
$in_bin ="001100110011";
$main_bin="000000000001";
$out = $in_bin & $main_bin;
print "out is $out\n";
for example?
or:
$blah="blah/blah/blah.bl";
($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?
Well, it looks like use doesnt accept an expression...it is however equivalent to:
BEGIN {
$modulename="abc.pm";
require $modulename;
}
and if you want to see the equivalent of use Module @list:
BEGIN {
$modulename="abc.pm";
require $modulename;
import...
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!
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])}...
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...
you should really use the split(" ") because the /\s+/ will put any leading spaces on the line as an element of the list ... the " " understands tabs, spaces etc too and wont put the leading spaces as an element:
$string = " a b c";
@list= split(/\s+/,$string)...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.