Win32 script cannot read command line argument.
Hi All, My script is unable to read argument when I'm executing it as: script.pl argument. However, when I'm running it as: perl script.pl argument - it works fine. I did associate perl scripts with Perl as explained in ActivePerl-Winfaq4.htm All my scripts, which doesnt require any arguments works file. I have WinXP with Service Pack 2. All appriciate any help to resolve it. Thanks, Vladimir
Re: Win32 script cannot read command line argument.
Hi David, Thanks a lot! It works -) My association was C:\Perl\bin\perl.exe %1 Vladimir - Original Message - From: Wagner, David --- Senior Programmer Analyst --- WGO [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED]; beginners@perl.org Sent: Wednesday, May 02, 2007 2:11 PM Subject: RE: Win32 script cannot read command line argument. -Original Message- From: Vladimir Lemberg [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 02, 2007 14:01 To: beginners@perl.org Subject: Win32 script cannot read command line argument. Hi All, My script is unable to read argument when I'm executing it as: script.pl argument. However, when I'm running it as: perl script.pl argument - it works fine. I did associate perl scripts with Perl as explained in ActivePerl-Winfaq4.htm All my scripts, which doesnt require any arguments works file. Your folder assocation looks like: C:\Perl\bin\perl.exe %1 %* If like this, then should be working. Been using this for what seems like forever. I have WinXP with Service Pack 2. All appriciate any help to resolve it. Thanks, Vladimir Wags ;) David R Wagner Senior Programmer Analyst FedEx Freight 1.408.323.4225x2224 TEL 1.408.323.4449 FAX http://fedex.com/us ** 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/
Capturing an external program return code
Hi All, My script is executing external program, which returns code i.e 0, -1, -2, -3 etc In case of error, I need to create log file according to error code. For example code -3 means missing input file use strict; use warnings; use Win32; system ( $program -f $program.cfg ); if ($? == -3) { print error message to log file } This is not working. Nothing is printing to the log file when I'm simulating -3 code. If I print $?, it shown 65280. I'll appreciate any help to solve this problem. Thanks, Vladimir
Re: Capturing an external program return code
Hi Tom, That was very helpful. Thanks a lot, Vladimir - Original Message - From: Tom Phoenix [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED] Cc: beginners@perl.org Sent: Tuesday, May 01, 2007 5:36 PM Subject: Re: Capturing an external program return code On 5/1/07, Vladimir Lemberg [EMAIL PROTECTED] wrote: My script is executing external program, which returns code i.e 0, -1, -2, -3 etc if ($? == -3) { This is not working. Nothing is printing to the log file when I'm simulating -3 code. If I print $?, it shown 65280. The value in $? is derived from the exit code, but it includes more information when a program fails. The full story is in the perlvar manpage, but you can recover the exit code something like this: my $exit_code = $? 8; $exit_code -= 256 if $exit_code 127; # fix sign The value 65280 shows an exit code of -1 by this method. One other detail can be very important: If your command invokes a shell to run another program, the exit code will be that of the shell, instead of the other program. To get the external program's exit code, Perl has to run the exernal program directly. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Win32::OLE packages
Hi to all, Sorry for asking the same question.. I beleave sombody have used win32:OLE module. From the Module description: OLE Automation brings VisualBasic like scripting capabilities and offers powerful extensibility and the ability to control many Win32 applications from Perl scripts. I need to Freeze Panes in my excel document. In VisualBasic this will look like this: Range(B2409).Select ActiveWindow.FreezePanes = True Do you know how to translate it on Perl language? For instance Range select looks like this: my $range = $xlBook-ActiveSheet-Range(A2:B2); Thanks in advance, Vladimir - Original Message - From: Vladimir Lemberg [EMAIL PROTECTED] To: beginners@perl.org Sent: Monday, March 26, 2007 4:22 PM Subject: Win32::OLE packages Hello All, Does anybody know which package in Win32:OLE will Freeze Panes and call Format Report method in excel document? Thanks in advance, Vladimir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Win32::OLE packages
Eventually, I figured it out. use strict; use warnings; use Win32::OLE; my $Excel = Win32::OLE-new('Excel.Application'); my $WorkBook = $Excel-Workbooks-Add; my $freeze_panes = $WorkBook-ActiveSheet-Range(B3)-Select; $Excel-ActiveWindow-{FreezePanes} = 1; - Original Message - From: Vladimir Lemberg [EMAIL PROTECTED] To: beginners@perl.org Sent: Tuesday, March 27, 2007 4:49 PM Subject: Re: Win32::OLE packages Hi to all, Sorry for asking the same question.. I beleave sombody have used win32:OLE module. From the Module description: OLE Automation brings VisualBasic like scripting capabilities and offers powerful extensibility and the ability to control many Win32 applications from Perl scripts. I need to Freeze Panes in my excel document. In VisualBasic this will look like this: Range(B2409).Select ActiveWindow.FreezePanes = True Do you know how to translate it on Perl language? For instance Range select looks like this: my $range = $xlBook-ActiveSheet-Range(A2:B2); Thanks in advance, Vladimir - Original Message - From: Vladimir Lemberg [EMAIL PROTECTED] To: beginners@perl.org Sent: Monday, March 26, 2007 4:22 PM Subject: Win32::OLE packages Hello All, Does anybody know which package in Win32:OLE will Freeze Panes and call Format Report method in excel document? Thanks in advance, Vladimir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Win32::OLE packages
Hello All, Does anybody know which package in Win32:OLE will Freeze Panes and call Format Report method in excel document? Thanks in advance, Vladimir
list of lists
Creating list of lists. Hi All, Could you help me to come up with idea how to generate list of lists on fly as follows: @LoL = ( [state, value, value], [state, value, value], [state, value, value],); State should be taken from hash %states where the state is a key. Value should be taken from function. I'm a perl beginner. This task looks very complicated to me :-( I'll appreciate any help. Thanks in advance, Vladimir
Re: list of lists
Hello Jeff, Thanks for help! I was trying to popolate LOL by adding each element on fly. Here my code: use strict; use warnings; use Win32; use Cwd; my @table; my $x = 0; my $y = 0; foreach my $category (sort keys %categories){ $table[$x][$y] = [ $category ]; $y ++; foreach my $zone (sort keys %na_zones){ my @list; open (F, $cwd\\db\\$na_zones{$zone}\\cat.cfg) or die; @list = grep {/CODE:$poi_categories{$category}/} F; close (F); #skip empty category if ([EMAIL PROTECTED]) { $table[$x][$y] = [ 0 ]; } else { my $poi_num = POI_Count (@list); $table[$x][$y] = [ $poi_num ]; } $y++; } $x++; } I have nothing when I print $table[1][1]\n; :-((( - Original Message - From: Jeff Pang [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED]; beginners@perl.org Sent: Thursday, March 22, 2007 5:46 PM Subject: Re: list of lists @LoL = ( [state, value, value], [state, value, value], [state, value, value],); State should be taken from hash %states where the state is a key. Value should be taken from function. Hello, It's just my guess,I think the state has some relation to the value,is it? It may write, my %hash = (...); my @lol; for (keys %hash) { push @lol, [ $_, func01($_), func02($_) ]; } Here func01 and func02 are the subroutines which accept the hash's key as their only argument and return a value for your use. -- http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: list of lists
Hello Jeff, Your solution is perfectly working. Thanks a lot! BTW I've solved my as well. I had to put } $y++; } $y = $x; - Here $x++; } I agree my code looks ugly -) Thanks, Vladimir - Original Message - From: Jeff Pang [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED]; beginners@perl.org Sent: Thursday, March 22, 2007 7:16 PM Subject: Re: list of lists Hello, I don't think the $x and $y are needed here since you're using Perl which is flexible enough for creating dynamic array for you. Here is my improvment version of your codes. my @table; foreach my $category (sort keys %categories){ my @tmp = ($category); foreach my $zone (sort keys %na_zones){ open (F, $cwd\\db\\$na_zones{$zone}\\cat.cfg) or die; my @list = grep {/CODE:$poi_categories{$category}/} F; close (F); my $poi_num = @list ? POI_Count(@list) : 0; push @tmp,$poi_num; } push @table,[EMAIL PROTECTED]; } (no test but I think it should most likely work.) use strict; use warnings; use Win32; use Cwd; my @table; my $x = 0; my $y = 0; foreach my $category (sort keys %categories){ $table[$x][$y] = [ $category ]; $y ++; foreach my $zone (sort keys %na_zones){ my @list; open (F, $cwd\\db\\$na_zones{$zone}\\cat.cfg) or die; @list = grep {/CODE:$poi_categories{$category}/} F; close (F); #skip empty category if ([EMAIL PROTECTED]) { $table[$x][$y] = [ 0 ]; } else { my $poi_num = POI_Count (@list); $table[$x][$y] = [ $poi_num ]; } $y++; } $x++; } I have nothing when I print $table[1][1]\n; :-((( -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
capture stdin and stderr
Hi All, My script is calling a Win32 program with two arguments: system ( $ARGV[0]\\program.exe, $File::Find::name, $ARGV[0]\\source); I want to capture STDOUT and STDERR from the program to log file system ( $ARGV[0]\\program.exe, $File::Find::name, $ARGV[0]\\source, 1$ARGV[0]\\log.txt, 21 ); Compiler gave me syntax error. And for sure the problem with this part: 1$ARGV[0]\\log.txt, 21. I was trying to double quote it and put commas but it didn't help. Is there any way to accomplish this task under Win32 environment? Thanks in advance, Vladimir
Re: capture stdin and stderr
Hi David, Would you please send this portion to me? Thanks, Vladimir - Original Message - From: Wagner, David --- Senior Programmer Analyst --- WGO [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED]; beginners@perl.org Sent: Tuesday, March 20, 2007 3:54 PM Subject: RE: capture stdin and stderr -Original Message- From: Vladimir Lemberg [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 20, 2007 15:21 To: beginners@perl.org Subject: capture stdin and stderr Hi All, My script is calling a Win32 program with two arguments: system ( $ARGV[0]\\program.exe, $File::Find::name, $ARGV[0]\\source); I want to capture STDOUT and STDERR from the program to log file system ( $ARGV[0]\\program.exe, $File::Find::name, $ARGV[0]\\source, 1$ARGV[0]\\log.txt, 21 ); Compiler gave me syntax error. And for sure the problem with this part: 1$ARGV[0]\\log.txt, 21. I was trying to double quote it and put commas but it didn't help. Is there any way to accomplish this task under Win32 environment? If using ActiveState, then see perlfaq8 and header How can I capture STDERR from an external command? If not AS, then reply back and I can that portion of the doc. Thanks in advance, Vladimir ** 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/
pattern match
Hi, I have a script, which suppose to find all *.xml files under the specified directory then process them. I'm facing the pattern match problem: use strict; use warnings; use Win32; use File::Find; @ARGV = Win32::GetCwd() unless @ARGV; my @dirs; find (\FindXml, $ARGV[0]); sub FindXml { return if !stat || -d; ( my $xml_file = $File::Find::name ) =~ /^.+\.xml$/; push ( @dirs, $xml_file ); } In this examples the pattern match /^.+\.xml$/ is not working and all files regardless of the extension have been assigned to $xml_file variable. # However, if I change parenthesis to count the matching, the pattern seems to work. sub FindXml { return if !stat || -d; my $xml_file = ( $File::Find::name =~ /^.+\.xml$/ ); print $xml_file; } I'll be really grateful for any help here. Thanks in advance, Vladimir
Re: pattern match
David, Thanks you very much! It works -) - Original Message - From: Wagner, David --- Senior Programmer Analyst --- WGO [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED]; beginners@perl.org Sent: Monday, February 12, 2007 12:46 PM Subject: RE: pattern match -Original Message- From: Vladimir Lemberg [mailto:[EMAIL PROTECTED] Sent: Monday, February 12, 2007 12:33 To: beginners@perl.org Subject: pattern match Hi, I have a script, which suppose to find all *.xml files under the specified directory then process them. I'm facing the pattern match problem: use strict; use warnings; use Win32; use File::Find; @ARGV = Win32::GetCwd() unless @ARGV; my @dirs; find (\FindXml, $ARGV[0]); sub FindXml { return if !stat || -d; ( my $xml_file = $File::Find::name ) =~ /^.+\.xml$/; push ( @dirs, $xml_file ); Then only get the files you want by: return if $File::Find::name !~ /^.+\.xml$/; push ( @dirs, $File::Find::name ); and push the $File::Find::name Wags ;) } In this examples the pattern match /^.+\.xml$/ is not working and all files regardless of the extension have been assigned to $xml_file variable. # However, if I change parenthesis to count the matching, the pattern seems to work. sub FindXml { return if !stat || -d; my $xml_file = ( $File::Find::name =~ /^.+\.xml$/ ); print $xml_file; } I'll be really grateful for any help here. Thanks in advance, Vladimir ** 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/
Re: problem with assigning a value
Hi Mark, Yes, I defined them outside of the while loop but it should not be a problem because I assigned them after changing directory. Here some debugging prints: I have for example 3 directories: a, b, c. Each one has .vsn file: a.vsn, b.vsn, c.vsn, on first iteration cwd = /home/vladimir/scripts/test/a $vsn = a.vsn woks ok on second iteration cwd = /home/vladimir/scripts/test/b $vsn = uninitialized not working on second iteration cwd = /home/vladimir/scripts/test/c $vsn = c.verworks ok If I'll define them inside while loop, it wont work either. Vladimir - Original Message - From: [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED] Cc: Perl Beginners beginners@perl.org Sent: Tuesday, June 07, 2005 2:23 PM Subject: Re: problem with assigning a value - Original Message - From: Vladimir Lemberg [EMAIL PROTECTED] Date: Tuesday, June 7, 2005 5:13 pm Subject: problem with assigning a value Hi, Hello I have a problem with assigning value to string. I'll be really grateful if someone will help me. use strict; use warnings; use Cwd; use Term::ANSIColor qw(:constants); $Term::ANSIColor::AUTORESET = 1; code fragment foreach (@dirs){ chdir $_; my $curdir = cwd(); my $vsn = glob (*.vsn); my $ver = glob (*.ver); print BLUE \n[$_]\n; opendir(DIR, $curdir) or die RED Unable to open $curdir: $!; while (defined (my $file = readdir DIR)) { next if -d $curdir/$file or $file eq zone.cfg or $file eq $vsn or $file eq $ver; #compressing system($program, $ARGV[0], $ARGV[1], $file) if $ARGV[0] eq -c; #decompressing system($program, $ARGV[0], $file) if $ARGV[0] eq -d; } closedir(DIR); chdir $cwd; } The problem is that on each even iteration of loop, strings my $vsn and $ver cannot be initialized. That is because you have already defined these variables outside of your loop. you can simpley say $vsn = Fo in your loop. By the way my $vsn = glob (*.vsn); may not due what you expact of it. HTH, mark G. Thanks in advance, Vladimir -- 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: problem with assigning a value
Thanks David! Works perfect with regex. -) - Original Message - From: Wagner, David --- Senior Programmer Analyst --- WGO [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: Perl Beginners beginners@perl.org Sent: Tuesday, June 07, 2005 4:57 PM Subject: RE: problem with assigning a value Vladimir Lemberg wrote: Hi Mark, Yes, I defined them outside of the while loop but it should not be a problem because I assigned them after changing directory. Here some debugging prints: I have for example 3 directories: a, b, c. Each one has .vsn file: a.vsn, b.vsn, c.vsn, on first iteration cwd = /home/vladimir/scripts/test/a $vsn = a.vsn woks ok on second iteration cwd = /home/vladimir/scripts/test/b $vsn = uninitialized not working on second iteration cwd = /home/vladimir/scripts/test/c $vsn = c.verworks ok If I'll define them inside while loop, it wont work either. Vladimir I tried a couple of things and I don't believe that glob is working as you would expect it to work. If you do not want the vsn or ver, then I would do a simple regex like ( $file =~ /.+\.(ver|vsn)/ ) If the file name portion needs to be ralted the directory you are working out, then it becomes a little harder, but I use glob very infrequently and when I have I have only used the glob against a directory that I want to work specific files otherwise a regex doing what I need to check is the way. Wags ;) - Original Message - From: [EMAIL PROTECTED] To: Vladimir Lemberg [EMAIL PROTECTED] Cc: Perl Beginners beginners@perl.org Sent: Tuesday, June 07, 2005 2:23 PM Subject: Re: problem with assigning a value - Original Message - From: Vladimir Lemberg [EMAIL PROTECTED] Date: Tuesday, June 7, 2005 5:13 pm Subject: problem with assigning a value Hi, Hello I have a problem with assigning value to string. I'll be really grateful if someone will help me. use strict; use warnings; use Cwd; use Term::ANSIColor qw(:constants); $Term::ANSIColor::AUTORESET = 1; code fragment foreach (@dirs){ chdir $_; my $curdir = cwd(); my $vsn = glob (*.vsn); my $ver = glob (*.ver); print BLUE \n[$_]\n; opendir(DIR, $curdir) or die RED Unable to open $curdir: $!; while (defined (my $file = readdir DIR)) { next if -d $curdir/$file or $file eq zone.cfg or $file eq $vsn or $file eq $ver; #compressing system($program, $ARGV[0], $ARGV[1], $file) if $ARGV[0] eq -c; #decompressing system($program, $ARGV[0], $file) if $ARGV[0] eq -d; } closedir(DIR); chdir $cwd; } The problem is that on each even iteration of loop, strings my $vsn and $ver cannot be initialized. That is because you have already defined these variables outside of your loop. you can simpley say $vsn = Fo in your loop. By the way my $vsn = glob (*.vsn); may not due what you expact of it. HTH, mark G. Thanks in advance, Vladimir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response *** 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
perl grep vs unix grep
Hi All, I have a script which works with text file over 1,5 - 2 GB. It takes me over 10 minutes to grep it and populate a list while unix shell is able to egrep it for 45 sec. open (LOGFILE,$_[1]) or die Cannot open LogFile file\n; local $/ = ''; @list = grep {/\|$pattern/} LOGFILE ; Is it possible to modify Perl grep that will work with the same speed as Unix egrep? I know that I can do like: #while (system(egrep,|$pattern,$_[1])){ #push(@list,$_)} but problem that log file has an empty line as record separator Thanks in advance, Vladimir
search engine for beginners.perl.org
Hi, Is there any way so search old posts via web? For example I want to ask some trivia question and I'm pretty sure that this question has been asked so many times. So before posting a new topic, I'd rather search the old ones regarding my problem. thanks in advance, Vladimir
calling Tcl script with ato arguments
Hi All, Could you help me to solve following problem: I need to execute tkl script with two arguments (input file and output file) within my Perl script: #!/usr/bin/perl -w use strict; use File::Basename; my @gdflist = `find . -name *.gdf`; my $gdf_number = scalar(@gdflist); my $counter = 0; foreach my $gdf (@gdflist){ my $base = basename $gdf; my $path = dirname $gdf; $base =~ s/(.*)(\.)/$1$2/; chomp($gdf); my $arg1 = $gdf; my $arg2 = $path/$1_patched.gdf; system patch_teleatlas_gdf.tcl $arg1 $arg2 or die patch_teleatlas_gdf.tcl is not working properly; $counter ++; print \{$gdf\}:PATCHED($counter of $gdf_number); } The problem that I'm receiving the die message patch_teleatlas_gdf.tcl is not working properly but then I manually assign arguments, Tcl script works with no problem. my arg1 = ./CSK/cansk47.gdf; my arg2 = ./CSK/cansk47_patched.gdf; system patch_teleatlas_gdf.tcl $arg1 $arg2 or die patch_teleatlas_gdf.tcl is not working properly; Any ideas? Should i use execvp(3) instead? Thanks in advance, Valdimir
date subtraction
Hi All, Could you advise me how can I subtract two dates? I have script: open FILE, /net/bazz/na_2004q3/db/uca/work/comp.log or die Can't open file: $!; @records = grep /Start Seq/, FILE; foreach (@records){ ($segID,@time) = (split) [2,4,6,7,9]; print $segID @time\n; } It produces these lines: Seq:1 Sat Nov 13 21:57:34 PST 2004 Seq:2 Sat Nov 13 22:05:17 PST 2004 Seq:3 Sun Nov 14 03:42:01 PST 2004 Seq:4 Sun Nov 14 21:57:34 PST 2004 I need to subtract dates to know how long each Seg took time. Is there any way to convert dates back to timestamps? Thanks in advance -Vladimir
Comparing two directories
Hi, Could you help me to find what's wrong in my script? I need to compare two directories and if file exists in both - print it. die Usage: 2 arguments must be passed i.e. file1 file2\n if @ARGV != 2; opendir DIR1, $ARGV[0] or die couldn't open $ARGV[0] for reading.\n; opendir DIR2, $ARGV[1] or die couldn't open $ARGV[1] for reading.\n; foreach $filename(readdir DIR1) { next if $filename =~/^\./; while (readdir DIR2){ if (-e $filename){ print $filename\n} } } closedir(DIR1); closedir(DIR2); Looks like I'm checking if exists in first directory but not in second. -Vladimir
Re: Comparing two directories
Actually, this is my script: foreach $filename(readdir DIR1) { next if $filename =~/^\./; while (readdir DIR2){ print $filename\n if (-e $filename); last; } } - Original Message - From: Vladimir Lemberg [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, October 27, 2004 5:14 PM Subject: Comparing two directories Hi, Could you help me to find what's wrong in my script? I need to compare two directories and if file exists in both - print it. die Usage: 2 arguments must be passed i.e. file1 file2\n if @ARGV != 2; opendir DIR1, $ARGV[0] or die couldn't open $ARGV[0] for reading.\n; opendir DIR2, $ARGV[1] or die couldn't open $ARGV[1] for reading.\n; foreach $filename(readdir DIR1) { next if $filename =~/^\./; while (readdir DIR2){ if (-e $filename){ print $filename\n} } } closedir(DIR1); closedir(DIR2); Looks like I'm checking if exists in first directory but not in second. -Vladimir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
previous element
I need to access previous element in array. File example: 1. SEG|2961|4| |B|N|000| | |91506|91506|Z|06| 37|0|1|Z|06|37|0|8954| 2. NAME|PARKSIDE AVE| | | |O|E|1399|1301|1398|1300|N|Y|Y| 3. 4. SEG|2962|4|A|B|N|000| | |91506|91506|Z|06| 37|0|1|Z|06|37|0|8954| 5. NAME|RIVERSIDE DR| | | |O|E|1799|1701|1798|1700|N|Y|Y| Pattern is PARKSIDE AVE. When I find it, I wont to display the previous line as well, because its one record. while(TF){ if (!/$pattern/i){next;} else{$counter++; print $_[-1]; #here I'm trying to display that previous line without success. print $counter: $_;} } And one more question: File example: #REDIRECT=/net/542/2003q4_2m/db/uca/zone.cfg REDIRECT=/net/542/2003q4_2m/db/uma/zone.cfg I need to get this path: /net/542/2003q4_2m/db/uca/ while (ZONECFG){ next if $_ =~ /^#/; ($path_todb) = $_ =~ /\/.*\//; } Instead of correct path I've got - 1. It looks like I'm assigning scalar value of $_ to my variable even if I surround path_todb in parenthesis Could you help me to resolve these two problems? Thanks in advance. -Vladimir
Re: previous element
Gunnar, thank you so much! - Original Message - From: Gunnar Hjalmarsson [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 21, 2004 4:40 PM Subject: Re: previous element Vladimir Lemberg wrote: I need to access previous element in array. I don't see any array. I see an extract from a file with records separated by blank lines. snip Pattern is PARKSIDE AVE. When I find it, I wont to display the previous line as well, because its one record. while(TF){ if (!/$pattern/i){next;} else{$counter++; print $_[-1]; #here I'm trying to display that previous line without success. print $counter: $_;} } Always use strict; use warnings; !! Also, please indent the code properly. The natural solution is to set the input record separator: local $/ = ''; while (TF) { print if /$pattern/i; } Read about $/ in perldoc perlvar. File example: #REDIRECT=/net/542/2003q4_2m/db/uca/zone.cfg REDIRECT=/net/542/2003q4_2m/db/uma/zone.cfg I need to get this path: /net/542/2003q4_2m/db/uca/ while (ZONECFG){ next if $_ =~ /^#/; ($path_todb) = $_ =~ /\/.*\//; } Instead of correct path I've got - 1. It looks like I'm assigning scalar value of $_ to my variable even if I surround path_todb in parenthesis No, you are not. The parentheses around $path_todb make it be assigned the return value from m// in list context. Have you read about the m// operator in perldoc perlop? If the /g option is not used, m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1 etc. are also set, and that this differs from Perl 4's behavior.) When there are no parentheses in the pattern, the return value is the list (1) for success. In other words, there are two possible changes you can do to make it return what you want: - use the /g modifier, or - use capturing parentheses in the regex -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- 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
hash. removing duplicates
Hi All, Could you help me resolve following problem. I have file: John Creamer: 123 345 123 678 345 Erick Morillo: 123 432 876 123 432 Cris Fortier: 678 123 987 123 345 I need to remove duplicated numbers from each line. The output file would be: John Creamer: 123 345 678 Erick Morillo: 123 432 876 Cris Fortier: 678 123 987 345 foreach (INFILE){ @temp = split/:/; print OUTFILE \n$temp[0]:; @numbers = split(/\s+/, $temp[1]); foreach $number (@numbers){ $freq{$number}++; print OUTFILE $number if $freq{$number}==1; } } The problem is that output file looks like this John Creamer: 123 345 678 Erick Morillo: 432 876 Cris Fortier: 987 So this script removes duplicatad numbers from all file but I need it per line :( Thanks in advance Vladimir
global matching
Hi, Could you help me to solve this problem? I have this file: foobar-45whatever-37hello16goodbye9#!!! snafu23skidoo---+30-50 I need to store all digits into list. As you can see there is no any obvious delimiter, so I'm using global matching open (INFILE, $ARGV[0]) || die cannot open $ARGV[0].\n; @digits = INFILE =~ /-*?\d+/g; print @digits; The problem is that @digits took only first line of my file. Thanks -Vladimir