Matching Over Multiple Lines
All, I know this has been asked many times, and I have read the documentation (perldoc -q matching over more than one line) and still can't make head or tails out of this. I have a problem where my pattern can be in one line, or span multiple lines. This is what I have so far (simplified): #!/bin/perl use warnings; use strict; $/ = ''; my $pat = 'EOF'; ^ AAA (.*)? ZZZ $ EOF my $file = ./mytext; while (DATA) { if ( /$pat/gms ) { print vv\n; print FOUND: $_; print ^^\n; } else { print vv\n; print NOT FOUND: $_; print ^^\n; } } __DATA__ AAAthis is the beginning of our text and it will continue over a few lines. In case you are not sure of what you see, you should check the document yourself.ZZZ This part has nothing to do whatsoever with the above text, but to be sure, you should not see this. AAABut this single line you should seeZZZ AAABut this double line, so the question is do you see itZZZ This part you will not see. I am not sure if I can use $/ to gobble up a paragraph, since we are reading and parsing XML files, which are around 10M in size. I need to do a non-greedy pattern match. Can someone tell me what I am doing wrong please? Thanks in advance, Jeff
Binary File Editing - Help!
Hello All, I am having a problem that should be very simple. I cannot figure this out for the life of me. I have a business need where I need to change a literal in a zip file from one string to another. Specifically, I need to change a filename embedded in the zip file (the one that would be extracted) with something else. Because the process is owned by another group and how things are configured here (running multiple runs simulatenously), I am stuck with trying to come up with a creative solution. Here is what I have: #--- start $ cat runme export WORKFILE=13646 export REALFILE=TRANS cat outfile.zip | perl -e ' use strict; use warnings; my $sw = 0; my $rc = 0; my $line = ; open(OUT, temp.zip) or die; while ($line = ) { if (! $sw) { $rc = $line =~ s/$ENV{WORKFILE}/ENV{REAL}/; print STDERR rc = $rc\n; print OUT $line; $sw++; } else { print OUT $line; } } close(OUT); ' $ runme rc = $ unzip -t temp.zip Archive: temp.zip testing: 13646OK No errors detected in compressed data of temp.zip. $ #--- end I don't understand why my $rc line is null either. The obvious solution is to change the input filename before the file gets zipped, but as mentioned, this is done by another group. Any help would be appreciated. Thanks so much, Jeff
Decrementing Characters
Hi, Simple question here. I need to decrement a character counter. Incementing works fine, but not decrementing. I have: #!/bin/perl use warnings; $var = 'm'; print var was $var\n; $var++; print var was $var\n; --$var; print var is $var\n; And I get: 0: rc-hp18:/home/dnxjjw5/dev $ x2.pl var was m var was n var is -1 I expected to see var is m in the last line. I know this is trivial, but I can't seem to see it. Thanks in advance!! Jeff
Parse Help
Hello, I have a string that I would like to parse and change the format. I'm not that good at 'map' and I'm just looking for a quick-and-dirty way of doing this. I've tried substr and split, but there has to be a simple way to do this. My text string looks like [20060911 14:47:11]p_var1=SD KQt=1 HZZ=2: 83,68//p_var2=QR44 KQt=1 HZZ=4: 77,57,52,52//p_var3=543210987 KQt=1 HZZ=9: 52,54,48,52,50,57,49,56,50//p_var4=001 KQt=1 HZZ=3: 48,48,49//p_var5=12345 KQt=1 HZZ=5: 49,50,51,52,53//p_var6=20060907 KQt=1 HZZ=8: 50,48,48,54,48,57,48,55//p_var7=000WR44 KQt=1 HZZ=11: 48,48,48,48,48,48,48,77,57,52,52//p_var8X KQt=1 HZZ=2: 83,68//p_var9= NULL (one lone line) I would like it cleaned up to look like p_var1='SD' p_var2='QR44' p_var3='543210987' p_var4='001' p_var5='12345' p_var6='20060907' p_var7='000WR44' p_var8='X' p_var9='' This is not 'production' or a school assignment, just the output from a file I need to make easier to read. Any help would be appreciated!!! TIA Jeff
Re: Parse Help
Too easy! THANKS JOHN!!! On 9/12/06, John W. Krahn [EMAIL PROTECTED] wrote: Jeff Westman wrote: Hello, Hello, I have a string that I would like to parse and change the format. I'm not that good at 'map' and I'm just looking for a quick-and-dirty way of doing this. I've tried substr and split, but there has to be a simple way to do this. My text string looks like [20060911 14:47:11]p_var1=SD KQt=1 HZZ=2: 83,68//p_var2=QR44 KQt=1 HZZ=4: 77,57,52,52//p_var3=543210987 KQt=1 HZZ=9: 52,54,48,52,50,57,49,56,50//p_var4=001 KQt=1 HZZ=3: 48,48,49//p_var5=12345 KQt=1 HZZ=5: 49,50,51,52,53//p_var6=20060907 KQt=1 HZZ=8: 50,48,48,54,48,57,48,55//p_var7=000WR44 KQt=1 HZZ=11: 48,48,48,48,48,48,48,77,57,52,52//p_var8X KQt=1 HZZ=2: 83,68//p_var9= NULL (one lone line) I would like it cleaned up to look like p_var1='SD' p_var2='QR44' p_var3='543210987' p_var4='001' p_var5='12345' p_var6='20060907' p_var7='000WR44' p_var8='X' p_var9='' This is not 'production' or a school assignment, just the output from a file I need to make easier to read. Any help would be appreciated!!! $ perl -le' my $text = q![20060911 14:47:11]p_var1=SD KQt=1 HZZ=2: 83,68//p_var2=QR44 KQt=1 HZZ=4: 77,57,52,52//p_var3=543210987 KQt=1 HZZ=9: 52,54,48,52,50,57,49,56,50//p_var4=001 KQt=1 HZZ=3: 48,48,49//p_var5=12345 KQt=1 HZZ=5: 49,50,51,52,53//p_var6=20060907 KQt=1 HZZ=8: 50,48,48,54,48,57,48,55//p_var7=000WR44 KQt=1 HZZ=11: 48,48,48,48,48,48,48,77,57,52,52//p_var8X KQt=1 HZZ=2: 83,68//p_var9= NULL!; my @p_var = $text =~ /([^]*)/g; print $_ for @p_var; ' SD QR44 543210987 001 12345 20060907 000WR44 X 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: Regex Multi-Line Matching
Hey Chris, I'm not spamming anyone. I had an error when I sent my email(s) so I resent it. Sorry you had to click the mouse an additional time to 'delete'. Jeff On 6/20/05, Chris Devers [EMAIL PROTECTED] wrote: On Mon, 20 Jun 2005, Jeff Westman wrote: Any help would be greatly appreciated. We heard you the first two times. Please stop spamming the list with the same question. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Regex Multi-Line Match
Hello Fellow Perlites, I'm having difficulty parsing a file and could use some help here. I've attached my code, output file, and sample job run. Basically, I want to read an Oracle TNS file (tnsnames.ora) and list the host name and service on that server based on this input file. A sample TNS entry is multi-lined and looke like this mysprdtmp = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxr)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysprd01) ) ) So, when the script runs, I would get this at end of job: mx01 = tmsprd01 mx16 = mystst04 mxp = mysdev07 mxq = mystst02 mxr = mysprd01 s0869u03 = rdmtst06 ux08 = rdmtst03 uxb = scsdev01 The script generally works fine, but it has a problem when I do not have a blank line in between these entries. In other words, if my input file has mysbse = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysbse) ) ) oemdev = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oemdev) ) ) it should recognize the new TNS listing and give me mxp = mysbse mxp = oemdev (along with the others I am parsing). Again, if I separate the two with a blank line, it works fine. But since this is a DBA-owned file, I cannot do this. My regex looks like my $tnsEntry = 'EOF'; ^ \s*\w+\s*=\s* \s+\(DESCRIPTION\s*= \s+\(ADDRESS_LIST\s*=\s* \s+\(ADDRESS\s*=\s*\(PROTOCOL\s*=\s*TCP\)\(HOST\s*=\s*(\w+)\)\(PORT\s*=\s*\d+\)\) \s+\)\s* \s+\(CONNECT_DATA\s*=\s* \s+\(SERVER\s*=\s*\w+\) \s+\(SERVICE_NAME\s*=\s*(\w+)\) # \s+\)\s* # \s+\) $ EOF Any help would be appreciated. I've been at this off and on for several days. Note, this is not a production file, but just a utility script. Thanks Jeff *** match #1 : ## axr ### mysprdtmp = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxr)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysprd01) ) ) *** RESULT : host= mxr, service= mysprd01 *** match #2 : mysprd01 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxr)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysprd01) ) ) *** RESULT : host= mxr, service= mysprd01 *** match #3 : ## axp ### mysbse = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysbse) ) ) oemdev = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oemdev) ) ) *** RESULT : host= mxp, service= mysbse *** match #4 : mysdev01 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysdev01) ) ) *** RESULT : host= mxp, service= mysdev01 *** match #5 : mysdev02 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysdev02) ) ) *** RESULT : host= mxp, service= mysdev02 *** match #6 : mysdev03 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysdev03) ) ) *** RESULT : host= mxp, service= mysdev03 *** match #7 : mysdev05 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysdev05) ) ) *** RESULT : host= mxp, service= mysdev05 *** match #8 : mysdev06 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =
RegEx Multi-Line Matching
Hello Fellow Perlites, I'm having difficulty parsing a file and could use some help here. I've attached my code, output file, and sample job run. Basically, I want to read an Oracle TNS file (tnsnames.ora) and list the host name and service on that server based on this input file. A sample TNS entry is multi-lined and looke like this mysprdtmp = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxr)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysprd01) ) ) So, when the script runs, I would get this at end of job: mx01 = tmsprd01 mx16 = mystst04 mxp = mysdev07 mxq = mystst02 mxr = mysprd01 s0869u03 = rdmtst06 ux08 = rdmtst03 uxb = scsdev01 The script generally works fine, but it has a problem when I do not have a blank line in between these entries. In other words, if my input file has mysbse = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysbse) ) ) oemdev = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oemdev) ) ) it should recognize the new TNS listing and give me mxp = mysbse mxp = oemdev (along with the others I am parsing). Again, if I separate the two with a blank line, it works fine. But since this is a DBA-owned file, I cannot do this. My regex looks like my $tnsEntry = 'EOF'; ^ \s*\w+\s*=\s* \s+\(DESCRIPTION\s*= \s+\(ADDRESS_LIST\s*=\s* \s+\(ADDRESS\s*=\s*\(PROTOCOL\s*=\s*TCP\)\(HOST\s*=\s*(\w+)\)\(PORT\s*=\s*\d+\)\) \s+\)\s* \s+\(CONNECT_DATA\s*=\s* \s+\(SERVER\s*=\s*\w+\) \s+\(SERVICE_NAME\s*=\s*(\w+)\) # \s+\)\s* # \s+\) $ EOF Any help would be appreciated. I've been at this off and on for several days. Note, this is not a production file, but just a utility script. Thanks Jeff -- perl script follows (tnsnames.pl): -- #!/usr/bin/perl # # tnsnames.pl -- reads tnsnames.ora, sorts by host name use warnings; use strict; my $host; my $name; my %tns; my @sortKeys; my $key; my $val; my $para; my $matchNbr; $/ = ''; # problem: tns entries with no line break are not distiquished my $tnsEntry = 'EOF'; ^ \s*\w+\s*=\s* \s+\(DESCRIPTION\s*= \s+\(ADDRESS_LIST\s*=\s* \s+\(ADDRESS\s*=\s*\(PROTOCOL\s*=\s*TCP\)\(HOST\s*=\s*(\w+)\)\(PORT\s*=\s*\d+\)\) \s+\)\s* \s+\(CONNECT_DATA\s*=\s* \s+\(SERVER\s*=\s*\w+\) \s+\(SERVICE_NAME\s*=\s*(\w+)\) # \s+\)\s* # \s+\) $ EOF die ORACLE_HOME is not defined!\n unless (defined($ENV{ORACLE_HOME} )); my $tnsFile = ./tnsnames.ora; open(F, $tnsFile) or die Could not open file $tnsFile: $!\n; while (chomp($para = F)) { undef($host); undef($name); if ($para =~ m[$tnsEntry]msxo) { $matchNbr++; print -x80, \n; print *** match #$matchNbr : $para\n; $host = $1; $name = $2; print *** RESULT : host= $host, service= $name\n; if ((defined($host)) (defined($name))) { $tns{$host} = $name; } } last if eof(F); } close(F); @sortKeys = sort keys(%tns); foreach (@sortKeys) { printf %-8s = $tns{$_}\n, $_; } -- sample input file follows (tnsnames.ora) -- # TNSNAMES.ORA Network Configuration File: /u01/app/oracle/product/9.2.0/network/admin/tnsnames.ora # Generated by Oracle configuration tools. # # history: # 05/27/04,kk Added rdmdev02 and scsdev01 # 06/01/04,js Added rdmtst02 and rdmtst03 per j.jonawski # 08/08/04,gv Added mysdev08 # 09/15/04,gv Added mystst04 # 09/20/04,cd Added mysdev04 ## mxp ### ## Reports server repserver_mysbse=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1960)) repserver_mysdev01=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1981)) repserver_mysdev02=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1982)) repserver_mysdev03=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1983)) repserver_mysdev04=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1984)) repserver_mysdev05=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1985)) repserver_mysdev06=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1986)) repserver_mysdev07=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1987)) repserver_mysdev08=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1988)) repserver_mysdev04=(ADDRESS = (PROTOCOL = TCP)(HOST = mxp)(PORT = 1989)) ## mxr ### mysprdtmp = (DESCRIPTION =
Regex Multi-Line Matching
My problem is simple. I want to parse an Oracle TNS file, listing host and the service it provides. A sample TNS entry is multi-lined and looks like this: mysprdtmp = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxr)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysprd01) ) ) The regex I am using to parse this looks like so: mysprdtmp = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mxr)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysprd01) ) ) My code snippit is like this: while (chomp($para = F)) { undef($host); undef($name); if ($para =~ m[$tnsEntry]msxo) { } The problem is, that this works great, EXCEPT for cases where I do not have a blank line separating two concatenated TNS entries (I only get the last one). Any help would be greatly appreciated. Thanks Jeff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Change ctime of a file ?
Is it possible to change the 'create timestamp' (ctime) of a file, and if so, how? This would be the perl equivalent of Unix' touch command. Thanks in advance! -Jeff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing shell variables to PERL
On Wed, 06 Oct 2004 16:21:31 -0700, John W. Krahn [EMAIL PROTECTED] wrote: [Please do not top-post. TIA] ok Jeff Westman wrote: On Tue, 05 Oct 2004 15:30:59 -0700, John W. Krahn wrote: Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env perl is case sensitive so that should be Env not env. You have to export the variable if you want perl to recognize it! Example: $ ABC=xyz $ perl -e 'print $ENV{ABC}\n' $ export ABC=xyz $ perl -e 'print $ENV{ABC}\n' xyz $ How is that related to using the Env module? Everything. The original poster asked how to display some varaibles from the shell. You CANNOT display those in perl unless you export them in the shell first. Have you tested it? I did. If you don't export it (as I showed in my example above), nothing is listed. Once exported, the perl command line is then aware of the environement. The point is, unless exported, the ENV module is useless since it is unaware of the parent environment. Disclaimer: this is for *nix systems; in DOS/Win systems, variables are always exported. John -- use Perl; program fulfillment -Jeff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing shell variables to PERL
You have to export the variable if you want perl to recognize it! Example: $ ABC=xyz $ perl -e 'print $ENV{ABC}\n' $ export ABC=xyz $ perl -e 'print $ENV{ABC}\n' xyz $ -Jeff On Tue, 05 Oct 2004 15:30:59 -0700, John W. Krahn [EMAIL PROTECTED] wrote: Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env perl is case sensitive so that should be Env not env. 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to Sort on a substr
Hi, I need to do a sort on a couple of column ranges. I want to be able to do a primary sort, on say, columns 21-25 and then a secondary sort on columns 40-49. Any ideas on how to approach this? TIA /j __ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: SQL PLUS
Bob Showalter [EMAIL PROTECTED] wrote: jason corbett wrote: What would I need to call SQL Plus into action for PERL? If you just need to execute SQL statements, use the DBI module and talk directly to the database. If you need to run existing sqlplus reports, use any of the standard facilities like system(), backticks, pipe open, fork/exec, etc. to call sqlplus from your perl script. If using DBD/DBI is not an option, a better choice would be to open sqlplus as a pipe stream, as in open (SQLPLUS, | sqlplus $SQL_LOG) or die Can't fork process; print SQLPLUS $oraId/[EMAIL PROTECTED]; print SQLPLUS set heading off\n; print SQLPLUS set pagesize 0\n; (etc) You could then run some basic commands. You can use the same idea to run plsql blocks. HTH Jeff __ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.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
Sort on Pipe-Delimited Column
Hello, I have some data that is pipe-delimited, that I would like to sort on the first column (numeric). The data looks like this: 173|Supertramp|The Very Best of Supertramp 19|Story, Liz|My Foolish Heart 54|Tchaikovsky|Nutcracker Suite 187|Tesla|Time's Makin' Changes: The Best of Tesla and once sorted, it should look like 19|Story, Liz|My Foolish Heart 54|Tchaikovsky|Nutcracker Suite 173|Supertramp|The Very Best of Supertramp 187|Tesla|Time's Makin' Changes: The Best of Tesla I tried usint sort {$a = $b} but got an error: Argument 173|Supertramp|The Very Best of Supertramp isn't numeric in sort at med2cdr.pl line 1. So I know I have to write my own sort sub-routine, perhaps using 'split', but I haven't a clue where or how to write that. Any help would be greatly appreciated! TIA Jeff __ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.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: excel
I just did this in fact using CSV.pm, worked great! See: http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm --- DiGregorio, Dave [EMAIL PROTECTED] wrote: Does anyone know, what is the best way to retrieve text data from an Excel Spreadsheet? I have tried the code below and it returns errors. I can not even get the name of the file to print! #! usr/bin/perl -w use strict ; use Spreadsheet::ParseExcel ; my $oExcel = new Spreadsheet::ParseExcel::Workbook ; my $oBook = $oExcel-Parse('Excel/Test.xls') ; print File : , $oBook-{File} , \n ; print Count : , $oBook-{SheetCount} , \n ; print Author : , $oBook-{Author} , \n ; I Thanks David __ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Installation Problem -- Text::CSV
Hi All, I am running Active Perl 5.8.0, and installed CSV.pm into c:\perl\lib\text. When I run the test.pl file with it I get C:\ perl test.pl 1..20 Can't locate auto/Text/CSV/autosplit.ix in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at C:/Perl/lib/AutoLoader.pm line 158. at C:/Perl/lib/Text/CSV.pm line 23 ok 1 Can't locate auto/Empty_Subclass/new.al in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at test.pl line 27 but I see an 'autosplit.pm' in c:\perl\lib. What's going on, and how do I fix it? Any help would be appreciated. TIA Jeff __ Do you Yahoo!? SBC Yahoo! - Internet access at a great low price. http://promo.yahoo.com/sbc/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Installation Problem -- Text::CSV
Bob Showalter [EMAIL PROTECTED] wrote: Jeff Westman wrote: Hi All, I am running Active Perl 5.8.0, and installed CSV.pm into c:\perl\lib\text. When I run the test.pl file with it I get C:\ perl test.pl 1..20 Can't locate auto/Text/CSV/autosplit.ix in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at C:/Perl/lib/AutoLoader.pm line 158. at C:/Perl/lib/Text/CSV.pm line 23 ok 1 Can't locate auto/Empty_Subclass/new.al in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at test.pl line 27 but I see an 'autosplit.pm' in c:\perl\lib. What's going on, and how do I fix it? Any help would be appreciated. Copying files around is not the proper way to install modules. If you use ActiveState, you should use the PPM tool to install modules if at all possible. To install Text::CSV, try: C: ppm install Text-CSV Worked perfect when installed correctly g Thanks for the help!!! Jeff __ Do you Yahoo!? SBC Yahoo! - Internet access at a great low price. http://promo.yahoo.com/sbc/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: starting perl
You need to add perl to your %PATH% or give it an explicite path name such as c:\ \perl\bin\perl -w -e print \ Hello, World!\n\; JW Charlie davis [EMAIL PROTECTED] wrote: From what I can remember I am running MSDOS version 6.0 (I thank) and the version of perl is perl 5.8 But when I type what it says in the book I am getting an error messagethat states that I have entered a bad command or filename what I am entering is c:\ perl -w -e print \ Hello, World!\n\; And then I get the error message. I must be doing something wrong but I can not figure out what it is. - Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs
RE: Is this possible? (file handles)
Venugopal P [EMAIL PROTECTED] wrote: Once you close the file, memory for the file handle will be deallocated. You can unlink file using the original file name. unlink (abc); This doesn't answer my question. I wanted to know if it is possible to remove a file using the FH name, not the variable name referencing it. Please see my original post below. Thanks again, JW -Original Message- From: Jeff Westman [mailto:[EMAIL PROTECTED] Sent: Thursday, April 01, 2004 2:02 AM To: perl_help Subject: Is this possible? (file handles) Hi, I want to remove an empty file using the file handle and not a variable name or literal name referencing it. Something like this: 1 #!/bin/perl 2 use warnings; 3 use strict; 4 no strict 'subs'; 5 6 open(F, abc) or die cant create file: $!; 7 close(F) or die cant close file: $!; 8 9 unlink(\*F) if -z (F); But, in this case, I get an error: $ runme.pl -z on closed filehandle F at ./x line 9. TIA, Jeff __ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Is this possible? (file handles)
Hi, I want to remove an empty file using the file handle and not a variable name or literal name referencing it. Something like this: 1 #!/bin/perl 2 use warnings; 3 use strict; 4 no strict 'subs'; 5 6 open(F, abc) or die cant create file: $!; 7 close(F) or die cant close file: $!; 8 9 unlink(\*F) if -z (F); But, in this case, I get an error: $ runme.pl -z on closed filehandle F at ./x line 9. TIA, Jeff __ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
date format using localtime()
Is there a way in perl to get the month/day/year using localtime WITHOUT using 'use POSIX qw(strftime)' or a system date call. Something using slices, maybe something like: print scalar ((localtime(time))[4,3,7]) expecting the result to be 03122004. Trivial question, thanks in advance. Jeff __ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.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: remove '\' with new-line
david [EMAIL PROTECTED] wrote: Jeff Westman wrote: I need a one-liner to convert all occurances read from a Unix pipe of 'backslash' + 'literal new line (hex 0a)' to become just 'literal new line (hex 0a)' That is, remove the '\' only when it preceeds a new-line. Again, this must be read from a pipe. This is what I have so far, but it doesnt do work: cat dfile | perl -pe 'BEGIN { $str = ord(10); } s!\\$str!$str!g' Suggestions?! that's because: [panda]# perl -le 'print ord(10)' 49 [panda]# perl -e 'print chr(10)' [panda]# you want chr(10): [panda]# cat dfile \abcd\xxx\yyy\ 1234\zzz [panda]# perl -pe 's.\\\n.\n.g' dfile \abcd\xxx\yyy 1234\zzz [panda]# perl -pe 'BEGIN{$n = chr(10)} s.\\$n.$n.g' \abcd\xxx\yyy 1234\zzz That did the trick. Thanks for catching my error. Jeff david -- s$s*$+/tgmecJntgRtgjvqpCvuwL$;$;=qq$ \x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65 \x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72 \x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32 \x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74 \x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response __ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.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
remove '\' with new-line
I need a one-liner to convert all occurances read from a Unix pipe of 'backslash' + 'literal new line (hex 0a)' to become just 'literal new line (hex 0a)' That is, remove the '\' only when it preceeds a new-line. Again, this must be read from a pipe. This is what I have so far, but it doesnt do work: cat dfile | perl -pe 'BEGIN { $str = ord(10); } s!\\$str!$str!g' Suggestions?! __ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.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
Help! Perl Substitution
I'm trying to help out another developer with a mini-Perl script. He has a file that contains one very long line, about 28M in size. He needs to do a replacement of all occurances of |^NEWLINE^|^ to a literal newline (HPUX, 0x0a or \n). When I ran this $ perl -ne 's/|^NEWLINE^|^/\n/g;print' loadFile it choked and gave me Out of memory during large request for 1073745920 bytes, total sbrk() is 604078796 bytes at -e line 1, line 1. Any suggestions would be extremely helpful. Thanks Jeff __ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help! Perl Substitution
Paul Johnson [EMAIL PROTECTED] wrote: On Thu, Feb 19, 2004 at 04:36:55PM -0800, david wrote: Jeff Westman wrote: I'm trying to help out another developer with a mini-Perl script. He has a file that contains one very long line, about 28M in size. He needs to do a replacement of all occurances of |^NEWLINE^|^ to a literal newline (HPUX, 0x0a or \n). When I ran this $ perl -ne 's/|^NEWLINE^|^/\n/g;print' loadFile it choked and gave me Out of memory during large request for 1073745920 bytes, total sbrk() is 604078796 bytes at -e line 1, line 1. if your system do not have memory to read in large chunk, you can easily break the chunks up by reading smaller chunks to process. for example, the follwoing reads 4k a time and process them: [panda]# perl -ne 'BEGIN{$/=\10} s/\|\^NEWLINE\^\|\^/\n/g; print' loadFile The trouble with this approach is that you will miss any separators which are split. Your example actually reads 10 bytes at a time, but using $/ is the right idea: perl -ple 'BEGIN { $/=|^NEWLINE^|^ }' loadFile This reads lines separated by |^NEWLINE^|^, chomps away the separator and prints the lines followed by a newline. perldoc perlrun perldoc perlvar Paul -- a million thanks -- your solution worked absolutely perfectly!! -Jeff __ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help! Perl Substitution
WC -Sx- Jones [EMAIL PROTECTED] wrote: Jeff Westman wrote: When I ran this $ perl -ne 's/|^NEWLINE^|^/\n/g;print' loadFile The program loads the ENTIRE loadfile and then splits characters at whitespace between characters and then prints every character followed by a newline. So, how big is loadfile? 28M. Isn't this pretty inefficient? Perl die-hards using perl s'///' over the traditional 'sed', but sed doesn't load the entire file into memory, hence the name, Steam EDitor. Sure, once in memory it runs fast, but it gave me quite unexpected results. Thanks to all who helped :) -Jeff __ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Emacs Wizards
Paul Kraus [EMAIL PROTECTED] wrote: Is there a way to easily have emacs comment out xnumber of lines. If something{ Then do Else Do } Alt 5 Ctrl - somecoolsequence I don't know #If something{ # Then do #Else # Do #} Sort of perl related assuming you hackers are using 'real editor' :) Something like ESC 5 ESC x replace-regexp enter ^ enter # should work (key sequence would be shorter if you have replace-regexp defined in a global keyset. (I love emacs, but vi is my tool of choice day-to-day ... much quicker vim is even better if you have it) HTH -Jeff __ Do you Yahoo!? Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE:Apel of VIM was Emacs Wizards
Paul Kraus [EMAIL PROTECTED] wrote: (I love emacs, but vi is my tool of choice day-to-day ... much quicker vim is even better if you have it) Why? I started with emacs just because it happened to be the 1st I heard about. Since you know both why does vim appeal to you over emacs? Other then size. I started off with the emacs version originally put out by MIT in the 80s. Loved it. Then came along gnuemacs, gemacs, xemacs, etc. All great improvements. Simply stated, running 'vi' from the command line (ie, start-up) is faster than *emacs. BUT, a TRUE emacs-person would rarely exit from it and run everything within it's extensive environment. To be honest? I can't remember half of the commands in emacs. But as stated, it is simply faster for most day-to-day tasts. JW __ Do you Yahoo!? Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: error.
Eric Walker [EMAIL PROTECTED] wrote: Does anyone know what this means... code.. for ($i = 0;$i = $size; $i+=$temp){ $type= split(::,shift (@hold)); } Warning: Use of implicit split to @_ is deprecated at .//test.pl line 21 Because perl is expecting an array (@_) to be returned and you are putting it into a scalar. That's my guess JW __ Do you Yahoo!? Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Apel of VIM was Emacs Wizards
Incidently, emacs has a 'dired mode' (directory editor) which is very nice... much like the old 'list' shareware in DOS land of the dark past you can bring up a list of files (like 'ls -l'), then view and selectively execute or delete all that you mark. It's very nice, and it can also be used when accessing remote servers. Not to mention it allows syntax highlighting. As driex pointed out, it is the start-up time that is preferred in vi/vim. But again, a true emacs die-hard never exits the editor and does all his/her tasks inside the of it. Not to mention, the learning curve for emacs is horrific. JW ~ Bradley A. Brown [EMAIL PROTECTED] wrote: I use vim on a daily basis from the command line and its syntax highlighting and color coding is very nice in my opinion. I'm not flaming here so don't take me wrong, but I heard it said once that knowledge of a language can never be replaced by an IDE. IDE's have always been a put off to me, but I can see their usefullness in many projects. Bradley -Original Message- From: Tim [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 14, 2004 3:47 PM To: drieux Cc: [EMAIL PROTECTED] Subject: Re: Apel of VIM was Emacs Wizards At 11:24 AM 1/14/04 -0800, you wrote: ... or trying to make that one liner perl -pie '' work right the first time... Isn't that what the i is for (with .bak, of course)? ;-) -- 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 __ Do you Yahoo!? Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: multiline matching
Jose Malacara [EMAIL PROTECTED] wrote: Can someone explain to me how to do multiline matching? I am trying to extract three consecutive lines from a datafile containing multiple records like this: Check out perldoc perlre What you should do is look at the 'm' (multiple line) option. HTH JW Name: Bob City: Austin State: Texas Address: 123 Whatever Age: 46 Name: Jose City: Denver State: Colorado Address: 118 Mystreet Age: 28 This is what I have so far, but it doesn't seem to work: #!/usr/bin/perl -w open FILE, file1 or die Can't open file!\n; while (FILE){ if ( /^Name: (.*)\nCity: (.*)\nState: (.*)/) { print Match found!\n; # ideally, I want to print the the lines found } } close FILE; But for some reason, it doesn't seem to like the (\n)'s in the regex. Any help would be appreciated! This is what I would like to return: Name: Bob City: Austin State: Texas Name: Jose City: Denver State: Colorado Thanks in advance, Jose __ Do you Yahoo!? Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Cobol format conversion
John McKown [EMAIL PROTECTED] wrote: FWIW - the best thing, IMO, is to change the generating program's PIC clause to: PIC S9(09)V.9(04) SIGN IS LEADING SEPARATE. This will take up two more characters in the output line. It will insert an actual decimal point and prefix the number with a + or a - sign. Much easier to process in a non-COBOL language. Sorry if this COBOL-talk offends any Perl-ites grin. Doesn't offend me ... we use COBOL, PERL and Java in our shop. On Sat, 10 Jan 2004, Olivier Wirz wrote: Hello, What is the best way to convert a numeric cobol format S9(09)V9(04) in a more readable way. For example: 0100} will be -1000. 0100{ will be 1000. The problem with the above is that you do not know where the decimal point is. I'm assuming this is in an ASCII file (hence the curley braces). Also there is no implication if these are COMP fields or not. Even so, the code you write will not be completely portable: A COMP-5 [binary] value with a negative sign will have a lower case 'p' instead of '}' if using Microfocus COBOL. I would just build a small conversion routine to parse and interpret according to how you expect it. For this to be on CPAN would be too general I think It works with substr and =~, but may be there is a module or another better way. Thank you. Olivier HTH, -JW __ Do you Yahoo!? Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Empty Array
What is the proper way to test if an array is empty ? TIA -JW __ Do you Yahoo!? Find out what made the Top Yahoo! Searches of 2003 http://search.yahoo.com/top2003 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Simple Hash Question
Hi I have a hash defined as my %flag3 = ( A = DBSpace backup thread, B = Begin work, C = Commiting/committed, H = Heuristic aborting/aborted, P = Preparing/prepared, R = Aborting/aborted, X = XA prepare ); I want to print out the value of the corresponding key -- without a loop iteration. The following works (displays 'value exists'), but is not what I want print value exists if exists $flag3{$pos3}; I want this to print the string. HELP PLEASE! TIA -- Jeff __ Do you Yahoo!? Find out what made the Top Yahoo! Searches of 2003 http://search.yahoo.com/top2003 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Simple Hash Question / NEVER MIND
DOH . DOH . NEVER MIND, user error ( - gun to head) DOH . DOH . DOH . Hi I have a hash defined as my %flag3 = ( A = DBSpace backup thread, B = Begin work, C = Commiting/committed, H = Heuristic aborting/aborted, P = Preparing/prepared, R = Aborting/aborted, X = XA prepare ); I want to print out the value of the corresponding key -- without a loop iteration. The following works (displays 'value exists'), but is not what I want print value exists if exists $flag3{$pos3}; I want this to print the string. HELP PLEASE! TIA -- Jeff __ Do you Yahoo!? Find out what made the Top Yahoo! Searches of 2003 http://search.yahoo.com/top2003 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: debugger
zentara [EMAIL PROTECTED] wrote: On 19 Dec 2003 09:16:10 -0700, [EMAIL PROTECTED] (Eric Walker) wrote: Hello all, When using the perl debugger, is there a way to load in the breakpoints and watch variables that I want from a file. I am using it now and as I am debugging I am finding problems but when I start the program over I have to re-enter all my breakpoints and watch variables again. Can these be listed in a file and then read by the debugger to ease the amount of things to enter? I know you are asking about the perl debugger, but the Tk version ptkdb has menu item for saving settings for the script, which save all breakpoints and watched variables. The GUI/Tk interface is superb check it out. If you don't have access to that (or can't install it like I can't [yes, even in my own HOME directory]), you can always save your breakpoints and watches to a plain text file, such as b 84 b 192 W $line W %custRec then just use good ol' fashioned cut/paste once you enter the line mode of the debugger -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Win32 Registry
Tim Johnson [EMAIL PROTECTED] wrote: Win32::TieRegistry will do what you want. use Win32::TieRegistry (delimiter = '/'); my $run = $Registry-{'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run'}; $run-{'MyApp'} = My Application; etc., etc. Suppose I had some DATA values listed under a branch (ie, VALUE). How do I delete those? I'm a little bit paranoid running something I've never done and hosing my registry. Can you give me an example... TIA Jeff -Original Message- From: Jeff Westman [mailto:[EMAIL PROTECTED] Sent: Fri 12/19/2003 10:12 PM To: perl_help Cc: Subject: Win32 Registry Hi, I need to access the Windows registry directly (not an exported 'reg' file). I am not familiar with Win32::Registry::File. Basically, I am trying to write a script that will do some 'cleanup' of known 'values' and 'data' strings that some uninstall applications neglect to cleanup. Any examples on how to use this would be appreciated (or other recommendations). TIA -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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 __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Align Text
Bill Jastram [EMAIL PROTECTED] wrote: Can you give an example of what you want your output to look like? From what I am hearing you say, you probably should be using 'format', as one already responded. -Jeff We're getting closer. But lets say the first name of the first field in the first row is 'Bill'. And the first name of the first field in the second row is 'Lanette'. This command will not compensate for the difference in the length of the two first names. So, the alignment of the second fields in each row will not be correct. And so on ... Does this help you understand where I'm headed? Bill __ yes, and if that won't work for you, check out the 'format' command, you can do lots of slick stuff with it, like centering. -Tom Kinzer -Original Message- From: James Edward Gray II [mailto:[EMAIL PROTECTED] Sent: Friday, December 19, 2003 9:16 AM To: Bill Jastram Cc: Perl List Subject: Re: Align Text On Dec 19, 2003, at 8:29 AM, Bill Jastram wrote: James: A coupe of things. #1. Pardon my ignorance, but I'm not sure how to use the list where I found the reply button to e-mail you directly. I could not find a way to add to the already existing 'thread'. Your help would be appreciated. The list is just another address you can send your messages too: [EMAIL PROTECTED] A lot of people just hit Reply All if their mail client has such a button. In the case of this message, that would send your answer to me and the list. #2. The challenge with the use of %20s is that in the next row of records the names will not be aligned (flush left) with the row above, if the names are not the same length. This is my dilemma. Correct, but they will be aligned flush right. For flush left, we just change the pattern a little: perl -e 'printf %-20s %-20s %-20s\n, James, Edward, Gray' JamesEdward Gray Does that answer your question? James -- 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 __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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
Win32 Registry
Hi, I need to access the Windows registry directly (not an exported 'reg' file). I am not familiar with Win32::Registry::File. Basically, I am trying to write a script that will do some 'cleanup' of known 'values' and 'data' strings that some uninstall applications neglect to cleanup. Any examples on how to use this would be appreciated (or other recommendations). TIA -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: foreach
Eric Walker [EMAIL PROTECTED] wrote: I got it so I need a counter which sends me to a for loop instead of a foreach. Thanks.. perlknucklehead I believe that 'for' and 'foreach' are completely interchangable. I remember reading somewhere that one was a synonym for the other. Maybe someone who is more familiar with the internals can confim that. -Jeff On Thu, 2003-12-18 at 17:07, Paul Johnson wrote: On Thu, Dec 18, 2003 at 04:57:26PM -0700, Eric Walker wrote: Hello all While traversing a loop across and array, how can I access array positions further down the array, like say if I am on a loop looking at position 23, how can I check the value of say position 24 or 32 while my loop counter is on position 23. Hmmm? Add 1 or 9 to your loop counter? Or have you not actually got a loop counter? If that is the case the easiest solution is probably to get one. Or have I completely misunderstood? Showing the code is usually more productive than simply describing the problem. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: alternating loop
Paul Johnson [EMAIL PROTECTED] wrote: On Thu, Dec 18, 2003 at 07:26:03PM -0500, Randy W. Sims wrote: On 12/18/2003 7:00 PM, James Edward Gray II wrote: On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote: Hello, been trying to come up with a way, while going through a loop to alternate a table cell color td/td See if this gets you thinking along the right lines: my $odd = 1; while () {# some kind of loop... if ($odd) { # do something $odd = 0; } else { # do something else $odd = 1; } } or my $alt; while () {# some kind of loop... if ($alt = !$alt) { # do something } else { # do something else } } or while () { if ($|--) { # do something HUH?? Why are you decrementing the $OUTPUT_AUTOFLUSH variable as an 'alternate' for loop???! Sorry, I don't follow you here. -JW } else { # do something else } } Oh, no. Hold on. On second thoughts ... -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: encrypting email address (to prevent spam)
Randal L. Schwartz [EMAIL PROTECTED] wrote: Sara == Sara [EMAIL PROTECTED] writes: Sara I am looking for a way to encrypt decrypt an email addy to Sara prevent spam while posting a message to discussion board. You also asked this, and I answered it, on the Perl Beginner's Mailing List at Yahoo. It's a waste of resource to post a question like this in multiple places, and unethical to not disclose that it has been asked in such a manner. What's unethical about it? What's wrong with posting it in multiple places?!! Not everyone on this list is a member of that list (and vice-versa). It is also very possible that someone on this list doesn't know the answer she needs (or doesn't bother to respond). It is not as if she is cross-posting (same organization, multiple lists). She is using any resources she has available -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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
Question for this Group ... dont flame me :)
Question for this group. And please don't flame me for asking this. Often times one writes in, asking how to do something fairly trivial, such as a date conversion from a non-standard format, or doing something else not require too much overhead. When asked for advice, nine times out of ten, the responded will refer the originator to such-and-such module at CPAN to download and install. I'm all for not re-inventing the wheel -- don't get me wrong. But if any of you are like me, you don't have access to install modules that run in a production environment. In my case, we have a couple of test servers and several hundred satellite servers that run 'production code'. So, installing a module is out-of- the-question. In my case, I am basically stuck with the perl [5.8] default libraries and modules. So, why is it that most of the solutions represented in this group tend to point to a CPAN module when the code for it isn't that hard (usually) to write? I'm not sure if using modules is a matter of convenience or necessity. While the solutions shown here will most often work, they aren't practical for Joe Programmer working in the corporate world (don't flame me! LOL) who doesn't have access to install as root or install on many many servers. My point being, it might be helpful to provide a solution such as See xxx::yyy at CPAN or my solution below I tend to believe that most people part this list distribution do coding for a living, while others just tinker with it on the side or are students. I suppose one way to point to a CPAN module and not have to install as root would be to install the module in the application library path. Thoughts? -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Question for this Group ... dont flame me :)
Guay_Jean-Sébastien [EMAIL PROTECTED] wrote: These answers are of course my own experience, but may be significant to understand the bigger picture. I reorder your points a bit in my reply :-) No problem :) So, why is it that most of the solutions represented in this group tend to point to a CPAN module when the code for it isn't that hard (usually) to write? a) It may not be hard to write, but it may have implications you don't see at first. For example, something dealing with dates. Does it need to deal with leap years? Does it need to deal with localized date formats? etc. etc. When you use a module like Date::Calc, the writer has thought of this, has written it when only thinking of what the module needs to do and do well, and has normally well tested each part of the module. I would definitely agree with you on Date::Calc. It's saved me more than once :) I don't know if this [specific] module is standard or not, but it was already installed on the servers, so I am guessing it is. I have NO problem with using 'standard' modules. Just like the C library -- it's just part of the industry standard. b) As new need arises in your program, using a module gives you access to other functionality which you would have to (again) write yourself if you were not unsing a module. But would you agree, that at least in some cases, it is almost as hard to use and understand a CPAN module then to write your own? Some of the documentation out there isn't the greatest :) [...] The other point is that when you're working on increasingly large projects, you reach a point where the amount of work for a given project would be too large (in time/money/etc) to be practical. That's when using modules for the general low-level parts is really useful. This is true, and if it is a tried and tested module (like Date::Calc or Net::FTP), I would totally agree with you. But I've used some modules from CPAN just as this group suggest grin just to find out it had a bug in it. When trying to contact the originator, the email address was defunct. So (being honest here) it makes me a little bit paranoid to use a module out there just because it is on CPAN. If it was one I've seen listed here many times, I would tend to trust that particular one. But face it, there are hundreds if not thousands of modules found in CPAN. And not all of them were written by the perl gurus :) Using modules can, in some cases, prevent you from thinking of a project as code, and more as how do I solve this problem. That's why in large projects, most people will want to make modules of their own for some parts of a problem that can be generalized (if an existing module doesn't already exist). It factors out some parts of the problem (once the module is well tested), and brings you to a higher level of abstraction. For larger projects requiring complex algorithms, I wouldn't hesitate to find something in CPAN. But if any of you are like me, you don't have access to install modules that run in a production environment. It's pretty easy to download a batch of modules onto one machine, and make a script to install them all onto multiple machines. Even if you can't do it yourself (because there's an evil SysAdmin who won't give you access) you can give him a package, containing the module tar.gz files and the script, and it won't be hard for him to install them. Most SysAdmins have developed a way of running a given command on the whole farm of servers... (chell scripts, normally) The admins here are a bit strange. They see no problem with me adding application code to do this or that, but they DO have a problem with code being added to /appl/site/perl5.8/lib [or whatever] since they (naively) feel that it would adversely affect the perl executable itself and/or other application developers using 'perl'. Yet I can install my own bug- ridden code code and bring the server to its knees. Go figure :) And if the SysAdmin still doesn't want to, go a bit higher, stating the fact that installing these modules will reduce your work load (increase your productivity), make your programs require less testing, etc. Managers react well to things that translate directly to dollar signs, and you're actually telling him the truth to boot! You're absolutely right, and that is perhaps where *I* need to make my case. Another responder to this question also suggested to at least evaluate the code from the module so as not to completely re-invent the wheen (good suggestion, BTW). Hope this helps, Yes it does, thanks. -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Wrapping Unix Command into Perl
Anthony J Segelhorst [EMAIL PROTECTED] wrote: I am trying to wrap the following Unix command into perl and having a few issues: find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \; I have tried (and nothing to seems to work): $temp = `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;` !system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; 1-- You are useing parens '( )' and should be using curley braces '{ }' in your exec. 2-- Why are you using -exec ls? -print already gives you the same output (unless you meant to write 'ls -l') -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Wrapping Unix Command into Perl
Anthony J Segelhorst [EMAIL PROTECTED] wrote: Anthony J Segelhorst [EMAIL PROTECTED] wrote: I am trying to wrap the following Unix command into perl and having a few issues: find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \; I have tried (and nothing to seems to work): $temp = `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;` !system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; Jeff Westman wrote: 1-- You are useing parens '( )' and should be using curly braces '{ }' in your exec. 2-- Why are you using -exec ls? -print already gives you the same output (unless you meant to write 'ls -l') 1. I am using {} and not () Well, that is the problem then. You have to use the curly braces. 2. Eventually I want to use this command to a remove rm, but I was testing with an ls. ok -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Wrapping Unix Command into Perl /correction
--- Jeff Westman [EMAIL PROTECTED] wrote: Anthony J Segelhorst [EMAIL PROTECTED] wrote: Anthony J Segelhorst [EMAIL PROTECTED] wrote: I am trying to wrap the following Unix command into perl and having a few issues: find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \; I have tried (and nothing to seems to work): $temp = `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;` !system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; Jeff Westman wrote: 1-- You are useing parens '( )' and should be using curly braces '{ }' in your exec. 2-- Why are you using -exec ls? -print already gives you the same output (unless you meant to write 'ls -l') 1. I am using {} and not () Well, that is the problem then. You have to use the curly braces. My bad, {} and () look the same in the font type, sorry. I tried your shell example and it worked for me (perl 5.8). But as also mentioned, you really should try to avoid shelling out, and use File::Find and unlink(). 2. Eventually I want to use this command to a remove rm, but I was testing with an ls. __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Get file size without downloading
Dan Anderson [EMAIL PROTECTED] wrote: On Wed, 2003-12-10 at 09:42, Bob Showalter wrote: usef wrote: Hi, FTP or HTTP? HTTP, but I want to know the method for FTP as well. Thanks -u I think that will work for FTP as well. Give it a try. If I type ls when I FTP into somewhere I get a listing of files and size. I would guess either: a) ls is a command in FTP b) there is a corresponding command in the FTP module you are using. In standard ftp, you can do 'size'. The Net::FTP for perl has a corresponding command also. When you are in standard ftp, just type ftp size yourFile and it will return something like ftp size yourFile 213 12523 where 213 is the message number and (in my case) 12523 is the size of the file. -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: -e with single quotes
Dan Muey [EMAIL PROTECTED] wrote: Hello group. I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? I've had this problem too, specifically when trying to run perl inside a Korn shell script. The following, though, will work for you on Win32 or *nix systems: $ perl -e '$q=chr(0x27);print joe${q}s mama' joe's mama -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Syntax a little funny ....
[EMAIL PROTECTED] wrote: I've just started trying to pick up a little perl. I'm breezing through Learning Perl and reading the perl docs. Excellent book. Do more than just breeze through it. Study it thoroughly, it's probably the single best starting place to learn perl. Here is some syntax I found a little funny, and I was hoping somebody could explain this too me: opendir(DIR, $some_dir) || die can't opendir $some_dir: $!; @dots = grep { /^\./ -f $some_dir/$_ } readdir(DIR); closedir DIR; The first and 3rd lines I have no problem with. The first line is better written as opendir(DIR, $some_dir) or die can't opendir $some_dir: $!; Note the use of 'or' instead of '||'. Precedence is extremely important, especially in perl where so much of the code can be short-circuited. Its that line with the grep in it. grep is obviously a built-in perl function. This is something I've seen before ... the output of the function readdir is trickling down to become the input of the function grep ? One minor problem, there is a comma missing before the 'readdir': @dots = grep { /^\./ -f $some_dir/$_ }, readdir(DIR); In C or Java you would write grep(readdir(DIR)) most likely ? No, you would use a while or for loop and then search for files not beginning with a dot. Sure, you can embed functions in perl (duh), but you have to put it into a loop construct. Here, in perl, it is implied. If that is so, what is all that business with the curly braces ? I thought curly braces are supposed to denote code sections ? You mean scope definition? Someone else can do a better job than I can on this, but you can use them basically whenever you want, or to combine sections of code/statements. So, it's like the output of readdir is trickling through the curly braces and then the output after this is trickling through grep ? It's a matter of precedence, really. I wouldn't say it is trickling, rather one function completing and passing it's result to the next one, just as you can in C/C++. If so, what is the input to the code section in the curly braces ? It's readdir(). So while-readdir, search for files (only) and test if they DONT begin with a dot, then store them into an array. Now that we have the files that match what we want, we close the directory since we don't need it any longer. Anyhow, all this is a bit weird to me, so I was hoping someone could shed some light on it. Perl can be written more 'C like', but why not take advantage of it's combination power whenever practical (and readable!). thanks and cheers, Hope this helps p.s. It seems some of my confusion comes from the fact that I am used to putting () around funtion calls. That still doesn't help with the curly braces though ... %^) Parens are often optional. When in doubt, use them. I never use them in simple print statemtents, but some functions like 'split', it just makes more sense. Your mileage may vary :) -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Syntax a little funny ....
James Edward Gray II [EMAIL PROTECTED] wrote: On Dec 8, 2003, at 11:28 AM, Jeff Westman wrote: [EMAIL PROTECTED] wrote: Here is some syntax I found a little funny, and I was hoping somebody could explain this too me: opendir(DIR, $some_dir) || die can't opendir $some_dir: $!; @dots = grep { /^\./ -f $some_dir/$_ } readdir(DIR); closedir DIR; The first and 3rd lines I have no problem with. The first line is better written as opendir(DIR, $some_dir) or die can't opendir $some_dir: $!; Note the use of 'or' instead of '||'. Precedence is extremely important, especially in perl where so much of the code can be short-circuited. Changing the || to or in the above line has no effect. Right, but too often one uses '||' and meant to use 'or'. It bites me every time g. However, as Jeff said, parens in Perl are often optional on subroutine calls and if we leave those out: opendir DIR, $some_dir or die can't opendir $some_dir: $!; We get the traditional Perl open() call and here it matters if we use || or or. Why do we write it like that? We like the way it reads. Its that line with the grep in it. grep is obviously a built-in perl function. This is something I've seen before ... the output of the function readdir is trickling down to become the input of the function grep ? One minor problem, there is a comma missing before the 'readdir': @dots = grep { /^\./ -f $some_dir/$_ }, readdir(DIR); The line compiles fine. The block version of grep() does not require a comma. Right again this is a case where using parens will get you :) .. I usually do: @dots = grep /^\./ -f $some_dir/$_, readdir(DIR); (no parens) perldoc -f grep No, you would use a while or for loop and then search for files not beginning with a dot. So while-readdir, search for files (only) and test if they DONT begin with a dot, then store them into an array. Now that we have the You say this twice, but that still doesn't make it true. Woops ... my bad! I think you need to reread that grep() call. ;) We're searching for files that DO begin with a dot here and placing them in the fitting @dots array. My bad :) If that is so, what is all that business with the curly braces ? I thought curly braces are supposed to denote code sections ? This is correct, it's a chunk of code. It will be executed once for each item returned by readdir(). p.s. It seems some of my confusion comes from the fact that I am used to putting () around funtion calls. That still doesn't help with the curly braces though ... %^) Parens are often optional. When in doubt, use them. I never use them in simple print statemtents, but some functions like 'split', it just makes more sense. I think the easiest rule to start learning with in use parens for your own subs and leave them off of built-ins, except when you need them to clarify/enforce precedence. I might add that parens can make your code more readable, but can also make it harder to read some times too. Parens often denote precedence, while braces tend to be used for scoping. This isn't a hard and fast rule though. Case-in-point, read: perldoc -f map -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Reading a log file, again
Tom Kinzer [EMAIL PROTECTED] wrote: Try this: Caveat: This all assumes LOTS about the format of your data being consistent, and so should be treated as a quick and dirty as opposed to anything resembling a robust application... I'm not sure what your intention with the script is, but is worth mentioning. -Tom Kinzer __SNIP__ my $input = '/appl/log/200301130.txt'; my $total; die Usage: Arg1: Input File to Scan. unless $input; open IN, $input or die Unable to open $input for reading, $!, stopped; while ( IN ) { if ( / Document Format/ ) { last }; } while ( IN ) { if ( / Total: -/ ) { last }; } while ( IN ) { if ( /^\s*\d+/ ) { chomp; s/\s*(\d+)\s*/$1/; $total = $_; printf Total: %010s\n, $total; last; } } close IN; __END__ Don't you need to do a seek(IN,0,0) in between each while loop? Why have three while loops; why not incorporate this into a single loop? -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: How to verify whether a directory exists
B. Fongo [EMAIL PROTECTED] wrote: I tried several alternatives to solve the problem, but failed. In most cases, the script couldn't create a directory if there is a text file with the same name. Rob's suggestion works better; except that it overrides the directory without warning - if it already existing. But it remians some how streng, because the content of the directory remains intact. mkdir $dir || die Failed to create $dir: $!\n unless -d $dir; It's okay anyway - as long as it's able to create a directory - even if a file (other than a directory) with the same name is found. Thanks guys The code snippet should be using 'or' instead of '|| to work properly. Consider if I put this snippet in a file called 'x'. When I try to create a directory also named 'x', it should fail, but does not tell me so: $ cat x #!/bin/perl -w $dir = $ARGV[0]; mkdir $dir || die Failed to create $dir: $!\n unless -d $dir; $ x x $ echo $? 0# success??? Now by changing '||' to 'or', we get what you'd expect: $ x x Failed to create x: File exists $ echo $? 17 # non-zero = failed, my OS is HPUX 11, dont know why I didnt get 255 (unsigned -1) Also consider what perl sees: Using '||': $ perl -MO=Deparse,-p x ($dir = $ARGV[0]); (-d($dir) or mkdir(($dir || die(Failed to create $dir: $!\n; x syntax OK Using 'or': $ perl -MO=Deparse,-p x ($dir = $ARGV[0]); (-d($dir) or (mkdir($dir) or die(Failed to create $dir: $!\n))); x syntax OK Hope that helps. -Jeff Rob Dixon wrote: Wiggins D'Anconia wrote: B. Fongo wrote: I want to use mkdir(blah blah, o777), but want to first find out whether the directory blah blah exists. I'm not if the -e option will bw right here. Let's say: unless (-e blah_blah) mkdir(blah_blah, 0777); # Is this okay? In general -e checks for file existence, -d checks to see if an existing file is a directory (or complains that the file doesn't exist). perldoc -f -e So your above code leaves a condition, where blah_blah exists but is *not* a directory which is likely to cause you problems. But since you haven't told us what happens in this failure case it is hard for us to say, but, if (-e blah_blah) { unless (-d blah_blah) { die File exists but is not directory; } } else { # don't forget to check mkdir's failure mkdir(blah_blah, 0777) or die Can't make directory: $!; } Just a note: There's no need to do a separate -e call to check whether a directory exists, -d won't throw an error. A simple die $dir is not directory unless -d $dir; Will check that $dir both exists and is a directory, which is probably all that is needed. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.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: Openning Files Names with Embedded Spaces
Rob Dixon [EMAIL PROTECTED] wrote: Jeff wrote: I am using Active Perl under Windoze 98. I am trying to open a file that has embedded spaces. I tried escaping the spaces as well, and that didn't work either. #! perl -w $file = c:\\win\\start menu\\programs\\system\\tbs montego\\_visit turtle beach web site.lnk; print file = $file\n; open(F, $file) or warn cannot open $file (continuing): $!\n; $file =~ s/ /\\ /g; print file = $file\n; open(F, $file) or die cannot open $file: $!\n; close(F); produces: file = c:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk cannot open c:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk (continuing): No such file or directory file = c:\win\start\ menu\programs\system\tbs\ montego\_visit\ turtle\ beach\ web\ site.lnk cannot open c:\win\start\ menu\programs\system\tbs\ montego\_visit\ turtle\ beach\ web\ site.lnk: No such file or directory The file _does_ exist and works fine if I use DOS 8.3 short names. Any suggestions? Hi Jeff. I agree with Tim, you've most likely got the filename slightly wrong. And by the way it's a lot safer and more readable to use single quotes unless you really need to interpolate variables or add control characters to a string. Try this short program so that you can see what Perl can see. It keeps shortening the path until an opendir succeeds and then dumps the directory. Then you can cut and paste the file names directly back into your code. use strict; use warnings; my $file = 'C:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk'; my $dir = $file; my $dh; ($dir) = $dir =~ /(.+)\\/ or die until opendir $dh, $dir; print dir = $dir\n; print map $_\n, readdir $dh; Just one thing: I presume your windows directory really is C:\win and not C:\WINDOWS? I hope this helps somehow, The program worked, and returned a directory listing in that directory. Basically, the problem I am still having is that I have a list of LNK files that I want to open. So when I use this statement: open(F, $f) or die cannot open file $f: $!\n; the spaces get confused somehow. The 'win' directory is correct back in the days of Windows 3.1, disk space was a premium, so I applied a tip I read once to use 'win' instead of 'windows' to minimize disk space since windows was used in so many places. I am opening the LNK files to dump some information, specifically, what the short cut key is (Win32::Shortcut has some short falls). __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Openning Files Names with Embedded Spaces
Tim Johnson [EMAIL PROTECTED] wrote: Granted, I'm on XP, but I can't seem to reproduce your error. I created a file at the path specified and it works perfectly. Are you sure that you have the exact filename and that you have access to it? (I guess it's windows 98, so you pretty much have access to everything...) Try pasting the printed out version of the file at the Run... prompt and see if you can open it. You may have to put double-quotes around it when you do this. The following code works for me: # use strict; use warnings; my $file = c:\\win\\start menu\\programs\\system\\tbs montego\\_visit turtle beach web site.lnk; print file = \$file\\n; open(F, $file) or warn cannot open $file (continuing): $!\n; while(F){ print; } close(F); # Of course, .lnk files are not text files, so if you really want to manipulate the link, you should use Win32::Shortcut. The above code you sent me gave me the same error: file = c:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk cannot open c:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk (continuing): No such file or directory readline() on closed filehandle F at x1.pl line 7. Also, the Win32::Shortcut has some short-comings, basically, it cannot break down the modifier codes for shortcuts, so I wrote my own. Thanks, Jeff __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Testing Perl on a Web Page
R. Joseph Newton [EMAIL PROTECTED] wrote: Try this: html head title Joseph's first Perl-based form /title /head body bgcolor=d0d0ff form method=POST action=FormTest.pl Name input name=Name type=text value= br Rank input name=Rank type=text value= br Serial Number input name=Serial type=text value= br input type=submit value=Launch Perl /form /body /html Then use CGI to get the parameters. perldoc CGI I got a '405 error', resource not available. I guess I'll just have to switch ISPs :) Thanks, -Jeff __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Testing Perl on a Web Page
Hello There, I would like to see if my ISP has perl available if one wanted to incorporate perl into a web page. Is there a quick and dirty web page I can upload to my ISP to test if perl is available and works ? I would also like to see what version of perl is running ? Could someone post something here that I can run ? TIA -Jeff __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing Perl on a Web Page
Dan Muey [EMAIL PROTECTED] wrote: Hello There, I would like to see if my ISP has perl available if one wanted to incorporate perl into a web page. Is there a quick and dirty web page I can upload to my ISP to test if perl is Try this: test.cgi #!/usr/bin/perl -w use strict; use CGI 'header'; print header(); print /usr/bin/perl Is VERSION $]; - Ftp in ascii - chmod to 755 However this is assuming: - Perl is at /usr/bin/perl - it's on a unix server - 755 is what it needs to be - .cgi is the extension you need - you're user is allowed All of which is basically what you're trying to find out. I'd just call your isp and say: - What is the path to Perl? - How do I upload/execute Perl scripts in my webspace? HTH Perfect! Exactly what I was looking for. I can deal with the paths/permissions/etc. I'm just trying to figure out how to get started. Oh, would I call this inside a web page with a SCRIPT tag or something? How do I point to the CGI script? Thanks again...! Jeff __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing Perl on a Web Page
Dan Muey [EMAIL PROTECTED] wrote: Hello There, I would like to see if my ISP has perl available if one wanted to incorporate perl into a web page. Is there a quick and dirty web page I can upload to my ISP to test if perl is Try this: test.cgi #!/usr/bin/perl -w use strict; use CGI 'header'; print header(); print /usr/bin/perl Is VERSION $]; - Ftp in ascii - chmod to 755 However this is assuming: - Perl is at /usr/bin/perl - it's on a unix server - 755 is what it needs to be - .cgi is the extension you need - you're user is allowed All of which is basically what you're trying to find out. I'd just call your isp and say: - What is the path to Perl? - How do I upload/execute Perl scripts in my webspace? HTH Perfect! Exactly what I was looking for. I can deal with the paths/permissions/etc. I'm just trying to figure out how to get started. Oh, would I call this inside a web page with a SCRIPT tag or something? No, it is it's own entity! More specific it's a server side language (IE the server processes it and returns the output) and script tags use client side languages (IE the browser processes the goods and does soemthgin based on that accordingly). (a very loose Interpretation anyway) Makes sense. How do I point to the CGI script? Open: http://www.yourwebsite.com/test.cgi In your browser. ok, got it (thanks) The problem is again that if the path isn't right or the permissions are wrong you will probably get an error which won't help much unless you know the info you're trying to find out anyway. It'll probably be faster just asking them and trying the example above with the info they give you to try it out. Thanks again...! No sweat! Everything makes sense and I appreciate your answering me. Now, I assume the script has to be executable so I will need telnet access. I tried (instead) to use a perl script I have that does ftp (including site-chmod) -- assuming I can't telnet. Anyway, I use this script all the time for work and I CAN connect to my ISP from Unix and list files. but when I tried running the equivalent perl script I have, it wouldnt even let me log in (but did connect at least). Is this a firewall problem? And if so, why would native FTP still work? (again, I was only using perl/ftp to do a chmod). I'll call my ISP to get other questions answered. Thanks again, Jeff __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Openning Files Names with Embedded Spaces
Hi, I am using Active Perl under Windoze 98. I am trying to open a file that has embedded spaces. I tried escaping the spaces as well, and that didn't work either. #! perl -w $file = c:\\win\\start menu\\programs\\system\\tbs montego\\_visit turtle beach web site.lnk; print file = $file\n; open(F, $file) or warn cannot open $file (continuing): $!\n; $file =~ s/ /\\ /g; print file = $file\n; open(F, $file) or die cannot open $file: $!\n; close(F); produces: file = c:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk cannot open c:\win\start menu\programs\system\tbs montego\_visit turtle beach web site.lnk (continuing): No such file or directory file = c:\win\start\ menu\programs\system\tbs\ montego\_visit\ turtle\ beach\ web\ site.lnk cannot open c:\win\start\ menu\programs\system\tbs\ montego\_visit\ turtle\ beach\ web\ site.lnk: No such file or directory The file _does_ exist and works fine if I use DOS 8.3 short names. Any suggestions? TIA, -Jeff __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Printing ASCII to Hex
James Edward Gray II [EMAIL PROTECTED] wrote: On Nov 18, 2003, at 10:33 AM, Jeff Westman wrote: There must be an easier way to convert a basic ascii string to hex. I tried using ord/chr/unpack/sprintf(%x) combinations and just dug my hole deeper. I'm not interested in using any additional modules, just straight, basic perl. This works, but exactly elegant: This one-liner produces identical output: perl -e 'print x, unpack(H*, some string), \n' Looks great. How could I have missed that?! That doesn't seem too complex, does it? Hmm, let's take a look... #!/bin/perl use strict; use warnings; my $str = some string; my $hex = unpack('H*', $str); The line above is 100% of the hex conversion. That's too cumbersome??? I doubt we can do much better. my $len = length($hex); my $start = 0; print x'; while ($start $len) { print substr($hex,$start,2); $start += 2; } print '\n; Ah, the long part! Printing two characters at a time. Any reason to do this? Originally, I wanted to print individually ASCII characters into hex, such as, x'73' x'6f' x'6d' (etc) Well, surely we can do it quicker: print 'x'; for (my $i = 0; $i length $hex; $i+=2) { print substr $hex, $i, 2; } print \n; Is that better? I'll let you decide. It's pretty C-looking, but that probably doesn't have to be a bad thing. Any of this help? Yep, thanks! -Jeff __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
When MUST you use 'map' ?
Hi, In my limited experience with perl, I've never had to use the 'amp' command, even though I see it used all the time. It seems to just be a short-cut of other commands/keywords that I've used. So, when do you HAVE to use 'map', when no other option makes sense?! -Jeff __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using Net::FTP for chmod (help needed ASAP)
Hi, Much to my surprise, when I run this code, it never returns 0 if it could not carry out the operation. $rc = $f-site(chmod 666 $remoteFile) or die ftp: Could not change permissions: $!\n; It seems to return a 2 on success, and a 5 if it could not access the file because of a different owner. My question is, what return code can I rely on? I need to be sure the permissions were set to '666'. Any suggestions? This is a emergency quick fix. Thanks in advance -Jeff __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using Net::FTP for chmod (help needed ASAP)
Wiggins d Anconia [EMAIL PROTECTED] wrote: Hi, Much to my surprise, when I run this code, it never returns 0 if it could not carry out the operation. $rc = $f-site(chmod 666 $remoteFile) or die ftp: Could not change permissions: $!\n; It seems to return a 2 on success, and a 5 if it could not access the file because of a different owner. My question is, what return code can I rely on? I need to be sure the permissions were set to '666'. Any suggestions? This is a emergency quick fix. Thanks in advance From the docs: Returns most significant digit of the response code. The response code is part of the FTP specification, response codes in the 200's are successes and responses in the 500's are failures, so it should be sufficient to check for a 2 and have that be success, a 5 makes failure and anything else is undefined. By looking at the 2 lesser significant digits normally a failure cause can be determined, but with 'site' that is system dependent (at least I think). This makes sense (now). Silly me, I thought non-zero was success. Using a truncated number from the RFC was definitely a mystery. I wish these packages followed a stricter standard. This helped tremendously, and I've resorted to using something like $perm = substr(sprintf(%s, $f-dir($remoteFile)), 1, 9); die Bad permissions\n unless ($perm =~ /rw-rw-rw-/); Thanks again! =) -Jeff __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: command-line
SilverFox [EMAIL PROTECTED] wrote: hey guys, i'm trying to grep some data from a log file and getting the following error. Any ideas??? [EMAIL PROTECTED] perl -e 'grep \Eliminating movie\ update.log |awk {'print \$5'}'; Can't find string terminator '' anywhere before EOF at -e line 1. You're mixing perl up with shell! Maybe what you are trying to do is: grep Eliminating movie update.log | awk '{ print $5'}' Or if you want this in perl, then you certainly would not be using 'grep' and not make a SYSTEM call to awk. ??? -JW __ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Recursion
Hi, I've never liked recursion but of course there are times where it is needed. I have a simple task that I am trying to do. Basically, I just want to list out my directories on disk, and then chdir to each one, print it out, and so on. Pretty basic, but I have a total mental block using recursion. Any quick help or tips would be appreciated. Thanks in advance, Jeff __ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Trivial 'unless' Question
Hi . very trivial ... is there a way or correct syntax to add an 'if' tp the following 'unless' statement? # this works fine ... print first\n unless ($counter); # ... but can I do something like print first\n unless ($counter) else { print second\n; # (syntax error) I know I can do this: #!/usr/bin/perl use warnings; use strict; my $counter = 0; unless ($counter) { print first\n; } else { print second\n; } but I wanted to put the 'unless' later in the statement. I couldn't find anything in the FAQ or perldoc on this one. TIA! -JW __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Trivial 'unless' Question
Steve Grazzini [EMAIL PROTECTED] wrote: On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote: # ... but can I do something like print first\n unless ($counter) else { print second\n; Not really. You could use the conditional operator, though. print $counter ? second\n : first\n; True, but I was looking for a way to do this with a somewhat buried unless keyword. TA -JW __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Aliases in Perl?
Hi, Are there 'aliases' in perl? For example, if I have a Korn shell script and a function named increaseCost(), I can do this: alias decreaseCose=increaseCost (passing a parameter in). of course this is a simplified example of what I want to do, but the point is to make it self-documenting. Maybe what I need is a reference ? TIA Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Aliases in Perl?
Bakken, Luke [EMAIL PROTECTED] wrote: Hi, Are there 'aliases' in perl? For example, if I have a Korn shell script and a function named increaseCost(), I can do this: alias decreaseCose=increaseCost (passing a parameter in). of course this is a simplified example of what I want to do, but the point is to make it self-documenting. Maybe what I need is a reference ? Personally, I've never (directly) used this feature, but here it is: use strict; sub foo { print Called foo\n; } *bar = \foo; foo(); bar(); Exactly what I am looking for! THANKS!!! -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Hash Print and Delete
Question: If I have an array and want to take the first element off and return it, I would do it like this: return (@myArray) ? shift(@myArray) : undef; How would I do similarly with a hash? I have something like this: return (exists $myHash{$val1} ) ? $Hash{$val2} : undef; But these leaves the value in the hash. I know I can save the value first, then DELETE it, and then return it. But I'd like to do it all in one step. TIA -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Hash Print and Delete
Rob Dixon [EMAIL PROTECTED] wrote: Jeff Westman wrote: If I have an array and want to take the first element off and return it, I would do it like this: return (@myArray) ? shift(@myArray) : undef; How would I do similarly with a hash? I have something like this: return (exists $myHash{$val1} ) ? $Hash{$val2} : undef; But these leaves the value in the hash. I know I can save the value first, then DELETE it, and then return it. But I'd like to do it all in one step. Hi Jeff. The 'shift' built-in returns 'undef' if its operand is an empty array. Likewise, 'delete' returns either the element deleted or 'undef' if it didn't exist. I didn't know 'delete' returned the value as well. Simple and perfect! It's also usual to omit 'return' on the last line of a subroutine, so you could just write: shift @myArray; and delete $myHash{$val1} to do what you want. I know perl returns the last value (statement?) by default, but doesn't it make it more readable (or self-documenting) to the next person who may come along what my intent is? -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Hash Print and Delete
Paul Kraus [EMAIL PROTECTED] wrote: Why wouldn't you just return(shift(@myarray) Yes, this works for a normal(?) array, but I was asking about hashes. As far as the hash why are you trying to remove it? I would assume it because you don't have a use for it outside of the scope of the subroutine. If so why don't you just make the hash scoped to the sub. Then you return the value you want and when the sub ends the hash is sent to the abyss? I'm deleting values in an array and a hash. Any left over values (or keys) signify an error and incomplete processing. Thanks -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Hash Print and Delete
Rob Dixon [EMAIL PROTECTED] wrote: [...snip...] return (exists $myHash{$val1} ) ? $Hash{$val2} : undef; Likewise, 'delete' returns either the element deleted or 'undef' if it didn't exist. [...snip...] I didn't know 'delete' returned the value as well. Simple and perfect! Having posted that I wondered whether you really meant what you wrote, i.e. that you want to return and delete $Hash{$val2} based on whether or not $myHash{$val1} exists. If that's correct then you still need the conditional expression, but it seemed a little unlikely? I guess there are other ways to do it and this may be reduntant since if I can't delete the hash value, it will return undef anyway. I know perl returns the last value (statement?) by default, The returned value is the value of the last executed statement as long as that statement was an expression. If not then I'm unclear as to the exact behaviour. [...snip...] returns the empty string (false, but not 'undef') Maybe somebody else knows? but doesn't it make it more readable (or self-documenting) to the next person who may come along what my intent is? IMO it would make it more obvious and wouldn't do any harm, but I've seen very little code written like that. It depends on whether you want your code to be 'familiar' or 'explicit'. Take a look at Since we use so many different coding languages in our shop, I just want to make the obvious definitive. Not everyone in this shop uses perl (most use Java), so I just wanted to be clear in my intention(s) in the code... -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: 2 newbie questions
Bee [EMAIL PROTECTED] wrote: hello all, I've just start my learning on perl, and recently still learning some basic syntax. So I hope my question is still making sense. I am now learning about how to write files and wondering is that possible to inserting / overwriting bytes in files ( text / binary ). and I am on Win32. Yes -- See perldoc read and perldoc seek. Basically, you find where in the file you want to replace text (the offset) then replace from there. Also, I am still learning how to use perldoc, and I found something is tutorial... so.. would anybody tell how many tutorials inside and what are they ? There are tons of online tutorials, but you should start with the perl documentation first. 'perldoc' has several forms, bascically, perldoc PACKAGE or DOCUMENTATION (example above) perldoc -q some search criteria (q = query) perldoc -f some function (example: perldoc -f print) Start with 'perldoc perl'. Hope that gets you started. -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Hash Print and Delete
Wiggins d'Anconia [EMAIL PROTECTED] wrote: On Fri, 10 Oct 2003 09:11:28 -0700 (PDT), Jeff Westman [EMAIL PROTECTED] wrote: I know perl returns the last value (statement?) by default, but doesn't it make it more readable (or self-documenting) to the next person who may come along what my intent is? Just so your opinion is backed up, I am very glad you said that and definitely appreciate it :-). But I am one of those lets be explicit about what I mean programmers, at least in any thing over 10 lines of code, but then I type faster than average which may be why I was never concerned about a few extra characters here and there, and I have never had to work over a 900, 1200, 2400, baud modem To put it another way, IMHO, you will *never* be frowned upon for including a 'return' when that is what you mean, but be prepared for a thrashing the first time you leave an open ended function that returns a value that it shouldn't and you break someone else's code because of it. Hi Wags, Not sure what you mean by 'open ended function'. Seems to me there would be more danger for someone to accidently add code below my last line in my function. Put another way, using a 'return' statement is explicit, whereas leaving it as the so-called perl way, leaves it implicit and open to someone adding their own code below that -- which would then blow up the expected returned value. I'm all for making things consise and effecient, but intent and clarity are equally important :) -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perl Debugger
Hi, I'm using perl version 5.6.1 for Unix (HPUX-11). I would like to be able to retain my 'watches' and breakpoints in between debug sessions. Is there a way to do this with the standard debug library that comes with perl? (I know I can save these with the ptkdb package, but I cannot get that to work since it requires Tk which requires gcc which requires other libraries ... long story, but that's not an option) TIA -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: convert UNIX timestamp
Mike Blezien [EMAIL PROTECTED] wrote: Hello, how can one convert a unix timestamp to a readable date/time format. I know there's a module to do this, but don't recall which one is used. IE. convert the unix timestamp: 1064616515 thx's Mickalo perl -e print scalar localtime() HTH -JW __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Is there a *nix shell variable for the path to perl?
Dan Anderson [EMAIL PROTECTED] wrote: Is there a (BA)SH/CSH/TSH/KSH variable to the Perl path? I am creating a script that uses Perl I want to be able to share over several servers. Instead of having my users edit the file manually (because I assume they would do something dumb) I want to create a shell script to edit the script for them. No, but you can create your own. Use something like: PERL=`which perl` Alternative, just call perl from the command line, such as $ perl yourScript.pl instead of $ yourScript.pl In the last case you would have to use a 'shebang' #!/path in the file itself, whereas calling it from the command line, it takes it from the $PATH. -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Order of Command Line Options
Hi, Why does the order of these options matter? In the first case, no output is produced, but it works correctly in the second case. I would have thought perl would have been smart enough to parse the command line options in any order. $ nslookup someServer | perl -en 'print qq($_);' $ nslookup someServer | perl -ne 'print qq($_);' Name Server: dns.myCompany.com Address: 10.18.68.22 Trying DNS Name:someServer.myCompany.com Address: 10.193.20.200 TIA -Jeff __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: May I know the perl version of following shellscript
--- Saifuddin_Bohra/[EMAIL PROTECTED] wrote: Hi, I am new to Perl. I have a follpwing shell script if [ -n `netstat -na|grep LISTEN |grep 1099` ]; then exit 0 else exit 1 fi I need the perl script for the same job. and how to use this in another perl program Any pointer ?? saifuddin This should work . #!/bin/perl use warnings; use strict; if ( length(qx(netstat -na|grep LISTEN |grep 1099)) 0 ) { exit(0); } else { exit(1); } (There are ways to shorten this, but this is the basic code I think you are looking for) -Jeff __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: why this is not working ??
--- John W. Krahn [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: On Wed, Aug 27, 2003 at 11:18:26AM +0530, T.S.Ravi Shankar wrote: open(STATUS, status.txt); for ($i=0; $i=98985;$i++) { system (process); if (($i%10)==0) { print STATUS \n\n $i iterations over !!*\n\n; } } close(STATUS); I'm not an expert, but shouldn't you add a space between % and 10? No, a space is not necessary there. In fact, if you use the print function instead of the print operator, you can remove all the non-quoted space characters. open(STATUS,status.txt);for($i=0;$i=98985;$i++){system(process);if(($i%10)==0){print(STATUS\n\n $i iterations over !!*\n\n)}}close(STATUS); However that is not very readable or maintainable. I ran this on my system (HP-UX, perl v5.6.1), changed process to date and it ran fine _as-is_. Could it be hosing on the external command here??! -JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: the File::Copy module
--- Saadat Saeed [EMAIL PROTECTED] wrote: Hello, Thanks for all your inputs now below you mentioned copy(qq(\\machine1\share\$file),qq(\\mahine2\share\$file)) sorry for my ignorance but what is qq In perl, there are many things to do things right. That is the beauty of perl, whether you use double backslashes or 'qq' or whatever. That is the wonderful thing about this list -- you learn new ideas how things are done in the real world! As for qhat 'qq' does, it behaves like double quotes. As you pointed out, it CAN make your code harder to read (!) sincemany people are not accustomed to it. For me, '' is more customary (with C/C++ or shell), so therefore, more readable. TO each their own :) also if I want to be smart and copy it to the c: drive of some user - assuming I am running the script from a Domain Admin login eg. \\machine1\c$\file then the dollar sign won't work as expected right - given my limited understanding will a \$ work then!!! Again, you need to escape the backslashes, either with qq{...} or ''. You want to have the '$' interpolated, meaning, it should not be escaped. You should be fine with what you have -- although you don't need to qualify as such in IMHO. -JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: the File::Copy module
Try: use strict; use warnings; ... my $returnValue = copy(machine1\\share\\file1,machine2\\share\\file2); unless ($returnValue) warn Copy failed: $!; (not tested) -JW --- Saadat Saeed [EMAIL PROTECTED] wrote: I was just reading the File::Copy module. Now on a pure Win32 environment will this work copy(\\machine1\share\file1,\\machine2\share\file2); Or should I do something else??? __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: the File::Copy module
--- Dan Muey [EMAIL PROTECTED] wrote: Try: use strict; use warnings; ... my $returnValue = copy(machine1\\share\\file1,machine2\\share\\file2); ^ I think that quote will cause problems. Have you tried single quotes also? That way you don't have to worry about properly escaping the \. copy('\\machine1\share\file1','\\machine2\share\file2') or die Copy failed $!; Just a thought That won't work if the write decides that file1 should be a variable instead. Just a thought :-/ Dmuey -JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Why executable?
--- Ovid [EMAIL PROTECTED] wrote: And as a word of caution, some like to add '.' to their path in order to save typing an extra two letters ('./' in front of the file name). Don't do this, though, as this is a major security hole. It depends on the flavor or Unix you are using. Also, if you are not running as root, there is no harm done. The './' simply tells Unix to explicitly use this file, don't look anywhere else. If there was another one in your path, it might use that one instead, hence the risk you are referring to. Again, this DOES depends on what flavor of *nix you are using. Using google to search for 'current directory path linux security hole' for many examples of this hole. One of the links said never to use find -exec rm -f since 'rm' does not follow symlinks. Again, this depends on what flavor you are using I'm currently on an HP-UX, and have used Solarias 8.x, AIX, and SysV5 I don't remember this being a problem. It COULD be a problem with Linux though -- I can't speak to that. Cheers, Ovid -JW --- fliptop [EMAIL PROTECTED] wrote: On Mon, 11 Aug 2003 at 22:36, Octavian Rasnita opined: [snip] OR:I've tried chmodding the perl script to 755, and I've tried running it OR:with: OR: OR:$ script.pl OR: OR:...but it didn't want to run, telling me that there is no command OR:script.pl, even though the script has a shebang line in it. you may want to try it again by specifying './script.pl' because if the directory '.' is not in your PATH, it won't find the file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Silence is Evil http://users.easystreet.com/ovid/philosophy/indexdecency.htm Ovid http://www.perlmonks.org/index.pl?node_id=17000 Web Programming with Perl http://users.easystreet.com/ovid/cgi_course/ __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net::Telnet - Variable won't change
--- SilverFox [EMAIL PROTECTED] wrote: Hey can someone help me figure out why the value of $file_exists won't change even when the file is mssing Thx. #!/usr/bin/perl -w $out=/home/laptop/scripts/perl/logs/resetmf.log; open OUT, $out or die Unable to open $out :$!; @site=(Machine1,Machine2); #telnet use Net::Telnet; $t = new Net::Telnet (Timeout=10, Errmode='die', Prompt='/\$ $/i'); foreach (@site) { $t-open($_); $t-login('username','passwd'); print OUT scalar(localtime), Conn EST: $_.\n; $dir=pf/working/output/Channel_status; @newdir=(/Machine1/$dir,/Machine2/$dir,/Machine9/$dir); for($x=0; $x = $#newdir; $x++) { $file_exists = $t-cmd (perl -e 'print 1 if (-s \$newdir[$x]\)') or warn Unable to execute: $!\n; if ($file_exists) { print Found it\n; }else{ print File Missing\n; } } } When I tried to run your cmd/perl line simply to test that part, I got: $file_exists = $t-cmd (ksh: syntax error: `(' unexpected Alternatively, you might try something simpler like: $file_exists = $t-cmd(test -f $newdir[$x] print 1 || print 0); -JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net::Telnet - Variable won't change
--- SilverFox [EMAIL PROTECTED] wrote: Jeff Westman wrote: --- SilverFox [EMAIL PROTECTED] wrote: Hey can someone help me figure out why the value of $file_exists won't change even when the file is mssing Thx. #!/usr/bin/perl -w $out=/home/laptop/scripts/perl/logs/resetmf.log; open OUT, $out or die Unable to open $out :$!; @site=(Machine1,Machine2); #telnet use Net::Telnet; $t = new Net::Telnet (Timeout=10, Errmode='die', Prompt='/\$ $/i'); foreach (@site) { $t-open($_); $t-login('username','passwd'); print OUT scalar(localtime), Conn EST: $_.\n; $dir=pf/working/output/Channel_status; @newdir=(/Machine1/$dir,/Machine2/$dir,/Machine9/$dir); for($x=0; $x = $#newdir; $x++) { $file_exists = $t-cmd (perl -e 'print 1 if (-s \$newdir[$x]\)') or warn Unable to execute: $!\n; if ($file_exists) { print Found it\n; }else{ print File Missing\n; } } } When I tried to run your cmd/perl line simply to test that part, I got: $file_exists = $t-cmd (ksh: syntax error: `(' unexpected Alternatively, you might try something simpler like: $file_exists = $t-cmd(test -f $newdir[$x] print 1 || print 0); -JW hmmmI'm still getting the same results. Think it have something to do with my shell (/usr/bin/sh). First, see if you can even do that shell test actually logged into that box, see what it returns. Second, I've had problems with telnet.pm -- kind of flakey at times, so you might try this instead: $file_exists = sprintf(%s, $t-cmd(test -f $newdir[$x] print 1 || print 0) ); That did the trick for me when I didn't get teh right results back. JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Telnet.pm and Unix prompt
Chris, --- Vidal, Christopher, SOLCM [EMAIL PROTECTED] wrote: Using the Telnet.pm mod, How do I put my unix prompt into the PROMPT scalar ? My unix profile prompt is : uid=`whoami` system=`hostname` PS1=$system $uid \\!: #! /opt/perl5/bin/perl require '/tools/mns/bin/Telnet.pm'; # $username = wannabperlguy ; $passwd = needslotsahelp; $t = new Net::Telnet (Timeout = 10, Prompt = '`hostname` `whoami`); $t-open(1.2.3.4); $t-login($username, $passwd); @lines = $t-cmd(/usr/bin/who); print @lines; I don't think you can do command substitution like this. Maybe if it was done before the compile stage (dunno). Try using a literal string. Example, I used this string to log in to 450 different servers (each had a the server name embedded in the prompt, s0001u01, s0002u01, s0003u01, etc): $t = new Net::Telnet ( Timeout= 15, Prompt = '/\([EMAIL PROTECTED]):.* $/' ); Note: special perl characters MUST be espcaped (as in the above). You can use '.' for single character substitution, and '*' for multiple characters (as you might expect). Note too that the trailing '$' above signifies end-of-string that telnet.pm will scan to indicate you're at a prompt (ie, my prompt might be: ([EMAIL PROTECTED]):/local/usr/apps . You're missing the '/' to indicate your prompt string set, and the final '$'. Concatenate the variables you want into a single variable and do something like Prompt = '/$myPrompt$/' ); HTH, JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
HTH
Hi, Okay guys, what does this mean? Several of you 'sign' with this. HTH (lol) JW __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: HTH
...and here I thought it meant hacker-to-hacker. Silly me. JW --- [EMAIL PROTECTED] wrote: On Thu, 24 Jul 2003 08:32:27 -0700 (PDT), Jeff Westman [EMAIL PROTECTED] wrote: Hi, Okay guys, what does this mean? Several of you 'sign' with this. HTH (lol) Or when used at the top of a posting, Hope This Helps as opposed to the bottom That Helped For those uninitiated if you ever see a term similar to this that you don't understand have a look here http://info.astrian.net/jargon/terms/h.html#HTH HAND, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using whence
David Parker wrote: Hi. I have a perl script that calls various programs. I would like to be able to verify that a given program is being called from the right place - what I would use whence for in the korn shell. I tried $path = `whence $cmdname`; but I don't get anything in $path. I'm undoubtedly missing something - I'm a beginner! Thanks in advance for any clues There's no 'whence' command in ksh that I know of... I think you want 'which' -- Brett http://www.chapelperilous.net/ I recently asked this question myself on another builtin ksh command. Steve, a regular contributer to this list told me the reason why my 'set' would not work: === begin cut == Actually, the shell isn't involved at all. Since there are no shell metacharacters in the string set, perl tries to exec set directly, using the C library function execvp(), which uses $PATH. $ strace -f perl -e 'qx(set)' 21 |grep exec execve(/usr/bin/perl, [perl, -e, qx(set)], [/* 22 vars */]) = 0 [pid 10527] execve(/bin/set, [set], [/* 22 vars */]) = -1 ENOENT [pid 10527] execve(/usr/bin/set, [set], [/* 22 vars */]) = -1 ENOENT [pid 10527] execve(/usr/X11R6/bin/set, [set], [/* 22 vars */]) = -1 ENOENT [pid 10527] execve(/opt/bin/set, [set], [/* 22 vars */]) = -1 ENOENT If you add a shell metacharacter, then perl will use the shell: $ strace -f perl -e 'qx(set;)' 21 |grep exec execve(/usr/bin/perl, [perl, -e, qx(set;)], [/* 22 vars */]) = 0 [pid 10594] execve(/bin/sh, [sh, -c, set;], [/* 22 vars */]) = 0 The same thing goes for system(), which is where this subtlety is documented. $ perldoc -f system === end cut So, in order to force the shell to be called using a builtin such as whence or set, simply add a ';' to the end of your string: #!/bin/perl use strict; use warnings; my $cmdname = date; my $path = `whence $cmdname;`; # note the embedded ';' print path - $path\n; And BTW, which checks your path only... whence checks the to see if the command is a builtin, a function, an alias (and finally) the path. which only checks the path -Jeff __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Weekly list FAQ posting
ok I want to bookmark this link, but it seems it is only one week's worth of questions, even though there is a [Prev Page][Next Page] on the page (which if it is a link, doesn't work). -JW --- Janek Schleicher [EMAIL PROTECTED] wrote: case wrote at Tue, 24 Jun 2003 15:17:48 +: 2.9 Other tips before posting to the list * Check the FAQs first once * Don't send questions asking ... will this work?. Try it first, then report errors and ask the list why it *didn't* work. A good answer to will this work?, is What happened when you tried it?. * If your email begins with I know this isn't the right place to ask this, but..., don't send it to this list :) If you know it doesn't belong, send it to where it does. * Check the FAQs first twice * Look at the archives, (http://archive.develooper.com/[EMAIL PROTECTED]/) to see if your question has already been answered on the list. * Have meaningful Subjects. Subject lines like Help!, and This isn't working! may be skipped by many people, and you may not get all the great help you want. Try to make your subject lines meaningful. For example, sprintf() trouble, or Confused about formats. :-) Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Reading from Pipe and Command Line
Could someone help me please? I am trying to write a simple script that will take input from the command line as well as input from a pipe. For example, the script should be able to do both of the following: $ cat someFile | myPerlScript.pl # from a pipe and $ myPerlScript.pl someFile # from command line This is what I have (very simple): #--- (begin) # #-- myScript.pl --# # #!/bin/perl use warnings; sub parseFile() { while () { ## I tried passing in \*STDIN or \*F but ## had nothing but problems with that # do some processing to the file # ... print . ; ## just to do something in the loop for now } } if (@ARGV) { $file = shift; open(F, $file) or die cannot open file $file: $!\n; parseFile; close(F); } else { parseFile; } #--- (end) # What is obvious to one is not always obvious to another. Thanks, JW __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading from Pipe and Command Line
--- Paul Johnson [EMAIL PROTECTED] wrote: On Wed, Jun 25, 2003 at 01:09:41PM -0700, Jeff Westman wrote: Could someone help me please? I am trying to write a simple script that will take input from the command line as well as input from a pipe. For example, the script should be able to do both of the following: $ cat someFile | myPerlScript.pl # from a pipe and $ myPerlScript.pl someFile # from command line This is what I have (very simple): #--- (begin) # #-- myScript.pl --# # #!/bin/perl use warnings; sub parseFile() { while () { ## I tried passing in \*STDIN or \*F but ## had nothing but problems with that # do some processing to the file # ... print . ; ## just to do something in the loop for now } } if (@ARGV) { $file = shift; open(F, $file) or die cannot open file $file: $!\n; parseFile; close(F); } else { parseFile; } #--- (end) # You are working far too hard. Remove most of your code: #!/bin/perl use warnings; while () { # do some processing to the file # ... print . ; ## just to do something in the loop for now } What is obvious to one is not always obvious to another. Quite. WAY too simple! I finally got it to work (see below) but obviously the easy solution is the best solution!!! #!/bin/perl use warnings; sub parseFile(*) { $fh = shift; while ($fh) { # do some processing to the file # ... print . ; } } if (@ARGV) { $file = shift; open(F, $file) or die cannot open file $file: $!\n; parseFile(\*F); close(F); } else { parseFile(\*STDIN); } Thanks for the help!! JW __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Odd Display using Perl5.8 in Debug
Hi, I have sort of a strange problem, and if anyone has a fix for it, please let me know. I don't know if this is perl-related or my software package. I am using 'Reflection X' for telneting. It's a great communications package, witht he exception of one annoying nuance. When I am debugging a perl script (using -d on the command line) AND using Perl 5.8, the first character of the current line when I print that variable wraps to the previous line, then displays the rest of the line where you would expect. This does not happen when I am running the same telnet software and using Perl 5.6.1 (we have both). Example of what I would see on the screen: +--+ | DB6 p $myFile / | | path/to/my/file | | ... | +--+ Note the leading '/' is on the same line as my print statement, and making it appear that when I display the contents of the variable, that it is in error (since it isn't obvious or intuitive to look at the preceeding line). Again, this is only when using Perl 5.8 and in debug mode, and works fine when I use 5.6.1. Sorry for the extra bandwidth, and thanks in advance for any ideas. Jeff __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Reading from STDIN from a pipe
Hi, I am trying to get my script to be able to read from the command line arguments as well as take input from a pipe. This is what I have basically: #--- (begin) # #!/bin/perl use warnings; sub parseFile() { while (F) { # do some processing to the file # ... } } if (@ARGV) { # this part works fine $file = shift; open(F, $file) or die cannot open file $file: $!\n; parseFile(\*F); close(F); } else { # trying to read from a pipe, such as 'cat file | thisScript.pl' parseFile(\*STDIN); } #--- (end) # When I run this, as in 'cat myFile | thisScript.pl', I get: Too many arguments for main::parseFile at ./x line 16, near *F) Too many arguments for main::parseFile at ./x line 21, near *STDIN) Help please. Jeff __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
perldoc - html format ?
Hi, Is it possible to reformat a perldoc in HTML format? I don't see this as an option to 'perldoc'. Thanks Jeff __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl debug
Peter- When I tried the 'y' command I got: DB3 y @a adWalker module not found - please install What's that about?! Jeff --- Peter Scott [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Steve Grazzini) writes: On Wed, Jun 18, 2003 at 05:21:06PM -0700, sandip das wrote: can anybody let me know how to print out values of certain variables in Perl Debug mode while doing single stepping ? Use 'p' or 'V'. 'x' is better for variables that contain references, since it will expand the references in a display like Data::Dumper output. From 5.8.0, there is also a 'y' command for examining lexical variables in higher scopes. -- Peter Scott http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]