output not in current directory
Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\perl test.pl 1(this will save the result in the current directory. How about saving the result to c:/perl/self/?) Thanks, Li __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: output not in current directory
chen li wrote: Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\perl test.pl 1(this will save the result in the current directory. How about saving the result to c:/perl/self/?) Your example saves the output in a file called '1'; presumably you knew that. But Windows would be a lot happier with it being called '1.txt' so that it knew what sort of contents it had and could default to using notepad (or something) to open it. Even better, so that /you/ knew what the contents were you could call it 'test-out.txt'. But on to your question... You can specify a path on the command line as well as an output file name, like this: C:\perl test.pl C:\perl\self\test-out.txt (Note that you need to use backslashes in the path on the command-line as the command prompt shell isn't as forgiving as Perl!) or you can reopen STDOUT within the program so that you don't have to redirect it on the command line: open STDOUT, '', 'C:\perl\self\test-out.txt' or die $!; (Either forward or backward slashes will do here.) 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: output not in current directory
On 9/10/06, chen li [EMAIL PROTECTED] wrote: Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\perl test.pl 1(this will save the result in the current directory. How about saving the result to c:/perl/self/?) Thanks, Li Hi Li, Google might help here: http://www.google.com/search?q=output+redirection+dos Does this: c:\perl test.pl C:\perl\self\test.out do what you want? - Jen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: output not in current directory
On 9/10/06, Jen Spinney [EMAIL PROTECTED] wrote: On 9/10/06, chen li [EMAIL PROTECTED] wrote: Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\perl test.pl 1(this will save the result in the current directory. How about saving the result to c:/perl/self/?) Thanks, Li Hi Li, Google might help here: http://www.google.com/search?q=output+redirection+dos Does this: c:\perl test.pl C:\perl\self\test.out do what you want? - Jen Ah, it seems Rob beat me to it. :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: output not in current directory
What is the code for this from the window promt(not within the script itself)? c:\perl test.pl 1(this will save the result in the current directory. How about saving the result to c:/perl/self/?) Thanks, Li Hi Li, Google might help here: http://www.google.com/search?q=output+redirection+dos Does this: c:\perl test.pl C:\perl\self\test.out do what you want? - Jen c:\perl test.pl C:\perl\self\test.out Yes it is what I want. Thanks, Li __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Current directory?
Hi there! I want to get the current environment variable (current directory), and I type like this: $currentpath = %ENV; and I get something like 37/64 instead of maybe usr/username/test How do I get current directory? /G -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Current directory?
[EMAIL PROTECTED] wrote: Hi there! Hello, I want to get the current environment variable (current directory), and I type like this: $currentpath = %ENV; and I get something like 37/64 instead of maybe usr/username/test How do I get current directory? perldoc Cwd John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Current directory?
#!/usr/bin/perl use strict; use Cwd; print getcwd,\n; #get the current path print $ENV{PATH}; #get the path from environment variable 2005/9/29, [EMAIL PROTECTED] [EMAIL PROTECTED]: Hi there! I want to get the current environment variable (current directory), and I type like this: $currentpath = %ENV; and I get something like 37/64 instead of maybe usr/username/test How do I get current directory? /G -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Jeff Peng [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Current directory?
Hi there! Thanx! I'll try that! :-) /G - Original Message - From: Jeff Peng [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: beginners@perl.org Sent: Thursday, September 29, 2005 10:27 AM Subject: Re: Current directory? #!/usr/bin/perl use strict; use Cwd; print getcwd,\n; #get the current path print $ENV{PATH}; #get the path from environment variable 2005/9/29, [EMAIL PROTECTED] [EMAIL PROTECTED]: Hi there! I want to get the current environment variable (current directory), and I type like this: $currentpath = %ENV; and I get something like 37/64 instead of maybe usr/username/test How do I get current directory? /G -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Jeff Peng [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.11.8/114 - Release Date: 2005-09-28 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Current directory?
On Thu, 29 Sep 2005 [EMAIL PROTECTED] wrote: I want to get the current environment variable (current directory), and I type like this: $currentpath = %ENV; Why do you expect this to do anything useful? You're assigning the contents of a hash into a single scalar. That will almost never do anything useful. As others noted, if you want a specific element from a hash, you have to name it explicitly -- $currentpath = $ENV{PWD}; -- or, as another person noted, use the Cwd module to do this in a more guaranteed to be portable way. But in any case, assigning a (full) hash to a scalar will never work :-) -- Chris Devers 6f9A/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Why am I getting data from Current Directory?
I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); print age of file: ; # age of file $Len = index(-M $_, .); print substr(-M $_, 1, $Len-1); print \n; }
RE: Why am I getting data from Current Directory?
Bret Goodfellow wrote: I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); print age of file: ; # age of file $Len = index(-M $_, .); Change the $_ to $File::Find::name ( Fully qualified name of file ) Is in the doc. Wags ;) print substr(-M $_, 1, $Len-1); print \n; } *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why am I getting data from Current Directory?
Bret Goodfellow wrote: I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? Once again (sigh): perldoc -f readdir readdir DIRHANDLE Returns the next directory entry for a directory opened by opendir. If used in list context, returns all the rest of the entries in the directory. If there are no more entries, returns an undefined value in scalar context or a null list in list context. If you're planning to filetest the return values out of a ^ readdir, you'd better prepend the directory in question. ^ Otherwise, because we didn't chdir there, it would have been ^^ testing the wrong file. ^^ opendir(DIR, $some_dir) || die can't opendir $some_dir: $!; @dots = grep { /^\./ -f $some_dir/$_ } readdir(DIR); closedir DIR; use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); Or simply: my $arg_lastchar = substr $ARGV[0], -1; $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; next if -d $arg_string/$_; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); printf '%-30s', $_; print age of file: ; # age of file $Len = index(-M $_, .); print substr(-M $_, 1, $Len-1); ^ You do realize that strings start at 0 and not 1? print int( -M _ ); print \n; Or combine all the print statements into one: printf %-30s age of file: %d\n, $_, int( -M _ ); } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Why am I getting data from Current Directory?
The File::Find::name didn't seem to make any difference. I still have to be in the directory that I want to search. Hmmm. -Original Message- From: Wagner, David --- Senior Programmer Analyst --- WGO [mailto:[EMAIL PROTECTED] Sent: Friday, March 11, 2005 3:13 PM To: Bret Goodfellow; beginners@perl.org Subject: RE: Why am I getting data from Current Directory? Bret Goodfellow wrote: I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; ## ## # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); print age of file: ; # age of file $Len = index(-M $_, .); Change the $_ to $File::Find::name ( Fully qualified name of file ) Is in the doc. Wags ;) print substr(-M $_, 1, $Len-1); print \n; } *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Why am I getting data from Current Directory?
Bret Goodfellow wrote: The File::Find::name didn't seem to make any difference. I still have to be in the directory that I want to search. Hmmm. -Original Message- From: Wagner, David --- Senior Programmer Analyst --- WGO [mailto:[EMAIL PROTECTED] Sent: Friday, March 11, 2005 3:13 PM To: Bret Goodfellow; beginners@perl.org Subject: RE: Why am I getting data from Current Directory? Bret Goodfellow wrote: I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; ## ## # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); print age of file: ; # age of file $Len = index(-M $_, .); Change the $_ to $File::Find::name ( Fully qualified name of file ) Is in the doc. Wags ;) print substr(-M $_, 1, $Len-1); print \n; It should. I ran a simliar script and had something like: printf %-30s: %5d\n, $File::Find::name, int(-M $File::Find::name); printed out the integer dates. As john K stated, you are working too hard and it can be generated as one line and I would just use printf and it's capabilities to line for you. For printing, you could use $- which has the filename and for testing then the $File::Find::name has the full path and filename. Wags ;) } *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why am I getting data from Current Directory?
Wagner, David --- Senior Programmer Analyst --- WGO wrote: Bret Goodfellow wrote: From: Wagner, David --- Senior Programmer Analyst --- WGO Bret Goodfellow wrote: I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; ## ## # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); print age of file: ; # age of file $Len = index(-M $_, .); Change the $_ to $File::Find::name ( Fully qualified name of file ) Is in the doc. Wags ;) print substr(-M $_, 1, $Len-1); print \n; The File::Find::name didn't seem to make any difference. I still have to be in the directory that I want to search. Hmmm. It should. I ran a simliar script and had something like: printf %-30s: %5d\n, $File::Find::name, int(-M $File::Find::name); printed out the integer dates. As john K stated, you are working too hard and it can be generated as one line and I would just use printf and it's capabilities to line for you. For printing, you could use $- which has the filename and for testing then the $File::Find::name has the full path and filename. The reason it didn't work is because Bret isn't using File::Find::find() so $File::Find::name is irrelevant. Also $- doesn't contain the filename: perldoc perlvar [snip] $- The number of lines left on the page of the currently selected output channel. Used with formats. (Mnemonic: lines_on_page - lines_printed.) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Why am I getting data from Current Directory?
John W. Krahn wrote: Wagner, David --- Senior Programmer Analyst --- WGO wrote: Bret Goodfellow wrote: From: Wagner, David --- Senior Programmer Analyst --- WGO Bret Goodfellow wrote: I am writing a script to list out a directory's contents, showing the number of days since modified. The problem I am having is that the script doesn't list out the modified time unless I change to the directory being listed. If I change to the directory I want to list, then all works okay. Is there a way to fix this script so that I don't have to run the script from the current directory? use strict; use warnings; use File::find; use File::stat; my $arg_length; my $arg_lastchar; my $arg_string; my $Len; $arg_length = length($ARGV[0]); $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = $ARGV[0]; print Argument: $arg_string\n; print length: $arg_length\n; print last character: $arg_lastchar\n; print Contents of $arg_string\n; opendir DH, $arg_string or die Couldn't open directory: $arg_string $!; ## ## # # Read one file at a time into $_ # # while ($_ = readdir(DH)) { next if $_ eq . or $_ eq ..; next if -d $_ ; # # append upto 30 blanks after the file name # # print $_, x (30-length($_)); print age of file: ; # age of file $Len = index(-M $_, .); Change the $_ to $File::Find::name ( Fully qualified name of file ) Is in the doc. Wags ;) print substr(-M $_, 1, $Len-1); print \n; The File::Find::name didn't seem to make any difference. I still have to be in the directory that I want to search. Hmmm. It should. I ran a simliar script and had something like: printf %-30s: %5d\n, $File::Find::name, int(-M $File::Find::name); printed out the integer dates. As john K stated, you are working too hard and it can be generated as one line and I would just use printf and it's capabilities to line for you. For printing, you could use $- which has the filename and for testing then the $File::Find::name has the full path and filename. The reason it didn't work is because Bret isn't using File::Find::find() so $File::Find::name is irrelevant. Also $- doesn't contain the filename: Sorry, but just saw the File::find and went right pass it. Also the $- should have been $_ if File::Find had been used, but wasn't. Bret, you can concatenate the $arg_string and $_ to get the file location or if you really want to read deeper into folder(ie, read into other sub folders) then use File::File::find and as stated above to do that. Again I apologize for seeing but not taking the time to really look at the code. Wags ;) perldoc perlvar [snip] $- The number of lines left on the page of the currently selected output channel. Used with formats. (Mnemonic: lines_on_page - lines_printed.) John -- use Perl; program fulfillment *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
current directory
Hello How can I find out the current directory? I call chdir, afterwards I should switch back to the old one. Thanks Urs -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: current directory
Hi Urs, You should look at Cwd: perldoc Cwd That capital C in Cwd is relevant. --Errin On Wed, 29 Sep 2004 15:24:06 +0200, Urs Wagner [EMAIL PROTECTED] wrote: Hello How can I find out the current directory? I call chdir, afterwards I should switch back to the old one. Thanks Urs -- 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
Re: current directory
Urs Wagner wrote: Hello Hello, How can I find out the current directory? I call chdir, afterwards I should switch back to the old one. perldoc Cwd John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Current Directory Name
Gidday All, How do I find out the name of the current directory I am in before I do chdir. Colin Johnstone -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Current Directory Name
use strict; use Cwd; $dir = cwd; print $dir; -Original Message- From: Johnstone, Colin [mailto:Colin.Johnstone;det.nsw.edu.au] Sent: Thursday, October 31, 2002 11:20 AM To: '[EMAIL PROTECTED]' Subject: Current Directory Name Gidday All, How do I find out the name of the current directory I am in before I do chdir. Colin Johnstone -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]