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])}...
...for 0-11
$year += 1900; # spec is years since 1900..
($year)=$year=~/(..)$/; # 2 digit date is fine..
if ($month =~ /^0(.*)/) {$month=$1}
if ($day =~ /^0(.*)/) {$day=$1}
$dateis = "$month.$day.$year";
if ($CMD__nicetime) {
if ($h >= 12)...
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)...
...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 read/write) which would have "," in it...so just do this:
$string =~ s/([*()])/\\$1/g...
...too...well, we can just go:
$text=" sdf adsf ds s s sd sdf s df dafs ";
foreach $line (split(/\n/,$text)) {
($line)=$line=~/^\s*(.*?)\s*$/m;
$line=~s/\s+/ /g;
print "new line : is \"$line\"\n";
}
so it will split the input line up into lines...
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]...
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...
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 =...
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.