some doubt
hi, How can i rename a file and check the size of file using perl? Also is there a way to call unix commands/system calls from perl?(Say i want to fstat() on a file and grab the stat struct results). Is there any way?? TIA -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Messing with Files [Was: some doubt]
It was Saturday, December 13, 2003 when Ajey Kulkarni took the soap box, saying: : hi, : How can i rename a file and check the size of file using perl? Use the rename() function. rename( $oldfile, $newfile ); perldoc -f rename() Use the file test operators, particularly -s. my $size = -s $file; perldoc -f -S : Also is there a way to call unix commands/system calls from perl?(Say i : want to fstat() on a file and grab the stat struct results). Is there any : way?? What you really want is the stat() function. my @properties = stat($file); perldoc -f stat If you want it to look more like a struct, use File::stat. use File::stat; my $prop = stat($file); print $prop-size; perldoc File::stat Casey West -- So we went to Atari and said, 'Hey, we've got this amazing thing, even built with some of your parts, and what do you think about funding us? Or we'll give it to you. We just want to do it. Pay our salary, we'll come work for you.' And they said, 'No.' So then we went to Hewlett-Packard, and they said, 'Hey, we don't need you. You haven't got through college yet.' -- Apple Computer Inc. founder Steve Jobs on attempts to get Atari and H-P interested in his and Steve Wozniak's personal computer. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: some doubt
Ajey Kulkarni wrote: [some stuff] Before this gets lost as a subthread I'm reposting it. I hope I catch most potential responses. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
File Operations and System Calls in Perl (WAS: some doubt)
Okay, I'll give you a few pointers, but first, please use a more descriptive subject line and start a new message when you start a new thread. The Perl documentation is found by running perldoc. To find the answers to your questions, try checking out: perldoc -f stat perldoc -q extern perldoc -f rename That should get you started -Original Message- From: Ajey Kulkarni [mailto:[EMAIL PROTECTED] Sent: Saturday, December 13, 2003 3:21 AM To: drieux Cc: Perl Perl Subject: some doubt hi, How can i rename a file and check the size of file using perl? Also is there a way to call unix commands/system calls from perl?(Say i want to fstat() on a file and grab the stat struct results). Is there any way?? TIA -Ajey
Some Doubt
Ajey Kulkarni wrote: How can i rename a file and check the size of file using perl? Also is there a way to call unix commands/system calls from perl?(Say i want to fstat() on a file and grab the stat struct results). Is there any way?? You can grab the size of a file using the -s operator on either a filename or an open filehandle. Check out: perldoc -f -s You can rename using the built-in 'rename' function on a filename. Check out perldoc -f rename You can execute shell commands using either the built-in 'system' call or the qx// operator. Check out: perldoc -f system or perldoc perlop and search for 'qx'. However I would /very strongly/ discourage you from shelling out of Perl unless there's something you can really cannot simply do otherwise. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: some doubt
Yes, do a search on google. I did this. -Jim - Original Message - From: Ajey Kulkarni [EMAIL PROTECTED] To: drieux [EMAIL PROTECTED] Cc: Perl Perl [EMAIL PROTECTED] Sent: Saturday, December 13, 2003 6:20 AM Subject: some doubt hi, How can i rename a file and check the size of file using perl? Also is there a way to call unix commands/system calls from perl?(Say i want to fstat() on a file and grab the stat struct results). Is there any way?? TIA -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
some doubt!
hi i have a prog which should create a file according to the date and name it $date.log and write something depending upon other things in it! Here is the code.. which refuses to work any clues.. ? TIA pravesh -- #!/usr/bin/perl -w $prefix_file = ` date '+%x' ` ; $log = .log ; print the date is $prefix_file ; $probe_logfile = $prefix_file . $log ; $probefile = probe.log ; $OUTFILE = $probe_logfile; my ($line_number) = 0; my ($yes) = 1; my ($no) = 0; open(probefile) or die(ERROR: $! \n); open(OUTFILE) or die (ERRROR :$! \n); while(probefile) { my @row_elems =split ; for (my $x=0; $x3 ; ++$x) { $rows[$x][$line_number] =$row_elems[$x] ; if($rows[1][$line_number] 0.1) { print OUTFILE $rows[0][$line_number] \t $yes \t; } else { print OUTFILE $rows[0][$line_number] \t $no \t; } } } John W. Krahn wrote: Julien Motch wrote: Hello , Hello, I am new to perl and here is my problem .I have written a programm which checks my mail and sends me instant message via gabber when 10 or more mail arrive or when a special sender writes me .The problem is that I receive the message head in one string .I want to isolate the line which contains the word 'Subject:' (by the way of grep do it ).Do you know a way to do that ? my ($subject) = $message =~ /\nSubject:\s*(.*)/; John -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: some doubt!
.--[ Pravesh Biyani wrote (2002/11/12 at 17:49:14) ]-- | | hi | i have a prog which should create a file according to the date and name | it $date.log and write something depending upon other things in it! | Here is the code.. which refuses to work | | any clues.. ? | | TIA | | pravesh | | -- | #!/usr/bin/perl -w | | $prefix_file = ` date '+%x' ` ; | $log = .log ; | | print the date is $prefix_file ; | | $probe_logfile = $prefix_file . $log ; | | $probefile = probe.log ; | $OUTFILE = $probe_logfile; | my ($line_number) = 0; | my ($yes) = 1; | my ($no) = 0; | open(probefile) or die(ERROR: $! \n); | open(OUTFILE) or die (ERRROR :$! \n); | `- You're not using open() correctly. You need to have something along the lines of: open(PROBE, $profile); open(OUT, $OUTFILE); while( PROBE ) { } You might want to re-read perldoc -f open. - Frank Wiles [EMAIL PROTECTED] http://frank.wiles.org - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: some doubt!
--- Pravesh Biyani [EMAIL PROTECTED] wrote: i have a prog which should create a file according to the date and name it $date.log and write something depending upon other things in it! Here is the code.. which refuses to work any clues.. ? $prefix_file = ` date '+%x' ` ; according to man, %x Current date representation. For example, 01/12/94. That means your filename probably has slashes in it, which the OS will interpret as a subdirectory path. add this line next and try it: $prefix_file = ` date '+%x' ` ; $prefix_file =~ s/\W+/_/g; That should convert 01/12/94 to 01_12_94, which is ok as a filename. __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: some doubt!
| $probefile = probe.log ; | $OUTFILE = $probe_logfile; | open(probefile) or die(ERROR: $! \n); | open(OUTFILE) or die (ERRROR :$! \n); You're not using open() correctly. You need to have something along the lines of: open(PROBE, $profile); open(OUT, $OUTFILE); Actually, while I MUCH prefer the two argument version, I believe the one argument version of open() *almost* works like this, except that he should have said open ($OUTFILE); I think. I hate that use, and don't use it, so I'm not sure __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: some doubt!
thanks verymuch.. the prgm working fine now!! cheers pravesh Frank Wiles wrote: .--[ Pravesh Biyani wrote (2002/11/12 at 17:49:14) ]-- | | hi | i have a prog which should create a file according to the date and name | it $date.log and write something depending upon other things in it! | Here is the code.. which refuses to work | | any clues.. ? | | TIA | | pravesh | | -- | #!/usr/bin/perl -w | | $prefix_file = ` date '+%x' ` ; | $log = .log ; | | print the date is $prefix_file ; | | $probe_logfile = $prefix_file . $log ; | | $probefile = probe.log ; | $OUTFILE = $probe_logfile; | my ($line_number) = 0; | my ($yes) = 1; | my ($no) = 0; | open(probefile) or die(ERROR: $! \n); | open(OUTFILE) or die (ERRROR :$! \n); | `- You're not using open() correctly. You need to have something along the lines of: open(PROBE, $profile); open(OUT, $OUTFILE); while( PROBE ) { } You might want to re-read perldoc -f open. - Frank Wiles [EMAIL PROTECTED] http://frank.wiles.org - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: some doubt!
Pravesh Biyani wrote: hi Hello, i have a prog which should create a file according to the date and name it $date.log and write something depending upon other things in it! Here is the code.. which refuses to work -- #!/usr/bin/perl -w $prefix_file = ` date '+%x' ` ; There is no need to run an external program to get the date as perl provides localtime() and gmtime(). Also, as Paul points out, the %x format uses slashes to separate the month, day and yesr fields which is not a valid file name character. The easiest way to create a formated date is to use the strftime function from the POSIX module. use POSIX 'strftime'; my $prefix_file = strftime '%Y%m%d', localtime; You will notice that I used the order year, month, day to make sorting by date easier. $log = .log ; print the date is $prefix_file ; $probe_logfile = $prefix_file . $log ; $probefile = probe.log ; $OUTFILE = $probe_logfile; The '' and '' prefixes are part of the open function not the file name. my ($line_number) = 0; my ($yes) = 1; my ($no) = 0; open(probefile) or die(ERROR: $! \n); open(OUTFILE) or die (ERRROR :$! \n); You should probably write these as: my $probefile = 'probe.log'; my $outfile = $prefix_file.log; open PROBE, '', $probefile or die ERROR $probefile: $!; open OUTFILE, '', $outfile or die ERROR $outfile :$!; while(probefile) { my @row_elems =split ; for (my $x=0; $x3 ; ++$x) { $rows[$x][$line_number] =$row_elems[$x] ; If you changed the order to $rows[$line_number][$x] this would be simpler. if($rows[1][$line_number] 0.1) { print OUTFILE $rows[0][$line_number] \t $yes \t; } else { print OUTFILE $rows[0][$line_number] \t $no \t; } } } my @rows; while ( PROBE ) { push @rows, [ (split)[0 .. 2] ]; print OUTFILE $rows[-1][0] \t , $rows[-1][1] 0.1 ? $yes : $no, \t; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]