On Monday, May 20, 2002, at 12:40 , Taylor Lewick wrote:
Taylor, as your code indicates you are still thinking in classical
shell terms of 'well fork a bunch of sub children and let
the kernel resolve the stdin to stdout connections.....' which is
where most of us start - nothing wrong with it.
What may help the process here is to think 'cat' but in 'perl'
#!/usr/bin/perl -w
use strict;
foreach my $file (@ARGV) { # for everything we see on the command line
# let us assume it is a
file for simplicity
if ( -f $file ) {
open(FH, "$file"); # normally we want to die
print $_ while(<FH>); # silly but a one liner
# could have been
while(<FH>) { print $_ ;}
# but that always
makes me think that the
# code is winking at
me...
close(FH);
}else{
print "cat: $file: No such file or directory\n";
}
}
# i'd go with Ovid's trick to do most of what you want to do the
# set the $fdate - so let us assume it is there ...
# all we need to do is stuff the 'awk' where it belongs
# also let us assume that you solved for $oldfile and $newfile
open(FILE, "> $newfile") or die "unable to open for write $newfile:\!";
open(FH, "$oldfile") or die "unable to open for read $oldfile:\!";
while(<FH>) { # now it will not wink at me
;-)
chomp; # remove the EOL
token(s) from
print FILE "$_,$fdate\n"; # just use the default $_ is good
enough
} # end of the while reading file handle
close(FILE);
close(FH);
exit(0); # OldGuyHabit - tell
the shell we
# are OK - and
to expressly bail out.
[..]
> In perl, I know I could do...
> $fdate=`date
-------------^
this is the unclosed back tick.
> open (FILE, ">/newfile");
> @file=`cat $oldfile`
this can get way messy if your 'oldfile' is 'big'
> foreach $item(@file) {
> chomp $item;
> print FILE "$item,$fdate\n";
> }
[..]
In the main a good beginning - since you grok the
basics of how to do some of this...
I of course would have taken an approach like I posted at
http://www.wetware.com/drieux/pbl/Sys/Admin/parsingFileFromOneToAnother.txt
also remember that strict and -w are your friend....
You'll need to feel safe with the <FILE_HANDLE>
approach - and yeah - you have to open and close them -
which was something the shell offloaded - because it
was never suppose to have the concept of a file descriptor.
As you get accustom to the stuff documented in
perldoc perl
you will find that you wander off the cliff into
the traditional 'coder' space....
ciao
drieux
http://www.wetware.com/drieux/pbl/
--------------
This space left intentionally blank.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]