Re: msql + cgi form parse error
This is a follow-up that I have been meaning to post for a month or so. The situation was a misbehaving form on a system I am maintaining. Further investigation of the code for the form revealed other problems, such as improper use of eval. The problem boiled down to -- rewrite or do spot fixes. Wiggins gave some great advice, and I ended up rewriting at least 50% of the code for the form. This was a particularly devilish problem because it turns out there were several things wrong. 1. The form was not properly limiting the length of the data it accepted in some fields. 2. Some fields in the database were not of the proper type/length to accept reasonable data (!?) 3. The perl code did very little to validate user inputs and correct problems with the data (!?) 4. The user interface looked like crud (not as big a deal, but important) and did not provide a verbose confirmation to users. I would have worked through this faster if I had not assumed that since the form had worked 'well enough' for a couple years it must only have a minor problem or two. The fix involved use of the quotemeta function (very handy!), fixing the sql field definitions, and several regex transformations to get rid of some common user errors (such as pasting in text that contained tabs)and a fair amount of time to improve the interface. Now it's very stable, and visibly better. I didn't go the route of binding variables (as Wiggins suggested), but might later. Another validation layer to consider is javascript to check data before submit. I guess my advice then is to not avoid reevaluating an entire system just because it's currently 'good enough' and you hope it's a quick fix. And thanks again. -Chris -- 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 with progress bar
On Fri, 16 Jan 2004 09:32:30 -0500, [EMAIL PROTECTED] (Zentara) wrote: Yeah, when they open the second window, they can do some tricks. I'm going to look closely at that today.I'm gonna figure something out. :-) Well I got it workingI can see why you had problems. 1. Did you get the perl package...or the php package? I know you mentioned php in your previous post. 2. It took some hacking to get it to work. He was deleting the files after uploading them, and din't mention that in the docs. Probably to not waste space on his server. Also the javascript didn't setup properly, and I had to manually add it to the script. 3. He didn't setup any method to save the files. I had to hack that. So after I test it a bit more, I'll put up a demo on my site, and show you what I did. The way he did it, was to setup a session-id, so when you submitted the file, it was saved to the session-id. Then he used javascript to start a second cgi, and passed the session-id to it. The second cgi would write to the new javascript window, and display filehandle size of the session-id upload. Yeah...I got all of what he was doing but didn't see that he wasn't saving any file to the server. I look forward to seeing what you come up with then I'll pick your brain some more. Thanks, Gerry -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: JPG FILE DOUBTS
John McKown wrote: On Thu, 15 Jan 2004, Andre Chaves Mascarenhas wrote: Hello i wanna know what Perl module can I use and what commands to do the folowing: 1-Check to see if the file is a valid jpg file You didn't say what OS. If you're running Linux (or almost any UNIX based system), then I'd do something like: if (`file $file` =~ /JPEG/) { print $file appears to be a JPEG file.\n; } else { print $file does not appear to be a JPEG file.\n; } This will tell you if the filename contains a certain string. That does not make the file a valid image file (besides, there's .jpg and .jpeg, both in uppercase and lowercase, so your pattern should be: /jpe?g/i if you just want to check the name. - Jan -- There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Client system variables
Hi! I'd like to get some system variables via web pages from CLIENT machines. Does anyone know any script that would do? Thank you!
Re: JPG FILE DOUBTS
Jan Eden wrote: John McKown wrote: On Thu, 15 Jan 2004, Andre Chaves Mascarenhas wrote: Hello i wanna know what Perl module can I use and what commands to do the folowing: 1-Check to see if the file is a valid jpg file You didn't say what OS. If you're running Linux (or almost any UNIX based system), then I'd do something like: if (`file $file` =~ /JPEG/) { print $file appears to be a JPEG file.\n; } else { print $file does not appear to be a JPEG file.\n; } This will tell you if the filename contains a certain string. Sorry! Please disregard my previous post, I overlooked the backquotes. - Jan -- How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine dark as the new standard. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Sending commands and viewing replies from a serial-attached appliance
Hi everybody. I need to communicate with an appliance, the consolle port of which is linked to my RedHat 7.2 system's serial port. I started writing a Perl programs that uses the basic filehandle syntax open(PORTA, "+/dev/ttyS0"); ... print PORTA $stringout; ... $answer = PORTA; I tested it connecting my serial port to a Windows workstation running Hyperterminal, and it worked out ok!Sadly, when I tried it on the needed connection, I got absolutely no response from the appliance. I blamed it on the different serial port configuration requested by the appliance (9600 bps, 8-bit, 1-stop, no parity, “flow control” = none), and so I turned to the more sophisticated "Device::SerialPort" module, which should provide the right tools to set the port parameters. I tested it again using Hyperterminal but this time, though I managed to get my strings sent, the replies I sent from the Windows hyperterminal never reached my Linux PC...naturally, it didn't work with the appliance either. I must certainly be going wrong somewhere, but I have no clue at all. Could you please help? I attach hereby the two versions of the program (both of which read the strings that must be sent from an input text file) and the script I used to set the port parameters. Thank you very much in advance. Best regardsBruno serial_old.pl - The first version of the program #!/usr/bin/perl -w # Routines # comunicate: adds a customary terminator to the string, which is then sent to # the serial port, the standard output and the logfile; finally it reads the # reply coming from the serial port and prints it on the standard output and # the logfile sub comunicate{ $terminator = \n; $stringout = $_[0].$terminator; print PORTA $stringout; print Sent: $stringout\n; print FOUT Sent: $stringout\n; ascspell($stringout); $answer = PORTA; print Received: $answer\n; print FOUT Received: $answer\n; ascspell($answer); } # ascspell: displays the ASCII codes for each character in a given string sub ascspell{ @array = unpack(C*, $_[0]); print [; foreach $ch (@array) { print $ch ; print FOUT $ch ; } print ]\n; } # Main open(FIN,$ARGV[0]) or die (error opening input file because: $!); @inner = FIN; close(FIN); open(FOUT, +serial_old.log); open(PORTA, +/dev/ttyS0); foreach $riga (@inner) { chomp($riga); comunicate($riga); } close(PORTA); close(FOUT); serconf.pl - The script that sets the port parameters and writes them to a config file == #!/usr/bin/perl -w use Device::SerialPort; # Initialisation $PortName=/dev/ttyS0; $ConfigurationFileName=./ttyS0.conf; $quiet=1; $lockfile=./lock; $PortObj = new Device::SerialPort ($PortName, $quiet, $lockfile) || die Can't open $PortName: $!\n; $PortObj-user_msg(ON); $PortObj-databits(8); $PortObj-baudrate(9600); $PortObj-parity(none); $PortObj-stopbits(1); $PortObj-handshake(rts); print Given configuration\n\n; print Port Name: $PortName\n; $baud = $PortObj-baudrate; $parity = $PortObj-parity; $data = $PortObj-databits; $stop = $PortObj-stopbits; $hshake = $PortObj-handshake; print B = $baud, D = $data, S = $stop, P = $parity, H = $hshake\n; $PortObj-write_settings; $PortObj-save($ConfigurationFileName) || warn Can't save $ConfigurationFileName: $!\n; = serial.pl - The Device::SerialPort version == #!/usr/bin/perl -w use Device::SerialPort; # Routines # comunicate: adds a customary terminator to the string, which is then sent to # the serial port, the standard output and the logfile; finally it reads the # reply coming from the serial port and prints it on the standard output and # the logfile sub comunicate{ $terminator = \n; $stringout = $_[0].$terminator; print PORTA $stringout; print Sent: $stringout\n; print FOUT Sent: $stringout\n; ascspell($stringout); $answer = PORTA; print Received: $answer\n; print FOUT Received: $answer\n; ascspell($answer); } # ascspell: displays the ASCII codes for each character in a given string sub ascspell{ @array = unpack(C*, $_[0]); print [; foreach $ch (@array) { print $ch ; print FOUT $ch ; } print ]\n; } # Initialisation $cfgfile=./ttyS0.conf;# created by serconf.pl $PortObj= tie(*PORTA,'Device::SerialPort', $cfgfile) || die Can't start $cfgfile\n; my $name= $PortObj-alias; my $baud = $PortObj-baudrate; my $parity = $PortObj-parity; my $data = $PortObj-databits; my $stop = $PortObj-stopbits; my $hshake = $PortObj-handshake; print Port: $name\nB = $baud, D = $data, S = $stop, P = $parity, H = $hshake\n; # Main
the file is there.. I know it is.
Hello everyone, I am starting to work on a script that is going to process a few files in some users directories. I thought I would do some checking on the file to make sure they are there and to make sure they are really files. I thought it was going to be pretty straight forward, until I ran it for the first time. Sometimes the script sees the file for one user but not the next ( that I know is there)? I must be misunderstanding something small, but I can't figure it out. Can anyone offer any suggestions? Thanks, Chad __ #!/usr/local/bin/perl eval 'exec /usr/local/bin/perl -S $0 ${1+$@}' if 0; #$running_under_some_shell use strict; use warnings; use Sys::Hostname; $|++; use vars qw( $server $pwdfile @users ); $server = hostname(); $pwdfile = '/etc/passwd'; # get users open (PASSWD,$pwdfile) or die Cannot open passwd file: $!; while (my $pwdline = PASSWD) { my ($user,$home,$shell) = (split /:/, $pwdline)[0,5,6]; next if ( $home !~ /^\/home/ || $shell !~ /^\/bin/ || $user eq ftp || $user eq www); push @users, $user; } close (PASSWD); foreach my $user(@users) { print Starting $user...\n; #print glob (/home/$user/*-logs/old/200312/access-log.31-*.gz).\n; $user = trim($user); my $decfile = glob (/home/$user/*-logs/old/200312/access-log.31-*.gz); my $janfile = glob (/home/$user/*-logs/old/200401/access-log.01-*.gz); if (!$decfile) { print \t\\Could not find Dec 31,2003 access log.\n; next; } elsif (!-f $decfile) { print \t\\Dec 31,2003 access log is not a file.\n; next; } elsif (!$janfile) { print \t\\Could not find Jan 01,2004 access log.\n; next; } elsif (!-f $janfile) { print \t\\Jan 01,2004 access log is not a file.\n; next; } else { print \t\\$user has both access logs.\n; } } # subs sub trim { my @in = @_; for (@in) { s/^\s+//; s/\s+$//; s/\n//g; } return wantarray ? @in : $in[0]; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Data File, turn fields on mulitple lines into records on one li ne.. .
Thanks Ron, will give that a try.. One more for everyone... In my perl script, I did a quick cheat by using the systems grep command... I tried: `/usr/bin/grep -v BLAH | /usr/bin/grep -v COW | /usr/bin/grep -v STUFF file1file2`; And this doesn't work. Sometimes it will get rid of STUFF. It seems to only act on the last grep I use. I tried escaping the pipes, but that didn't work. Any ideas? Thanks... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: the file is there.. I know it is.
chad kellerman said: Hello everyone, I am starting to work on a script that is going to process a few files in some users directories. I thought I would do some checking on the file to make sure they are there and to make sure they are really files. I thought it was going to be pretty straight forward, until I ran it for the first time. Sometimes the script sees the file for one user but not the next ( that I know is there)? I must be misunderstanding something small, but I can't figure it out. Can anyone offer any suggestions? You are using glob in a scalar context. This is not what you want. perldoc -f glob foreach my $user(@users) { print Starting $user...\n; #print glob (/home/$user/*-logs/old/200312/access-log.31-*.gz).\n; $user = trim($user); my $decfile = glob my ($decfile) = glob (/home/$user/*-logs/old/200312/access-log.31-*.gz); Finding a use for the current behaviour is left as an exercise for the reader. -- 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
Re: multiline matching
On Jan 15, 2004, at 8:30 PM, Kenton Brede wrote: Thanks for the great explanation. I've been working with the code above since I need more hash practice, trying to keep on track with the original poster's question. The code below works fine except I can't figure out how to put one \n between the two records like - Name: Bob City: Austin State: Texas Name: Jose City: Denver State: Colorado If I place print \n; after the print line I get double spaces between all lines. If I place it outside the last for loop I get double spaces between the two records. What I have below just prints them in one block. Hope that all made some sense:) I'm with you. See below. Thanks for any help, Kent #!/usr/bin/perl use warnings; use strict; You forgot a very important line from my example right here: local $/ = ''; # enter paragraph mode Your code was reading line by line, then working on just that line. You never had more than one entry in the hash at a time. My example reads until it sees one or more blanks lines (paragraph mode), then works with an entire contact at once. That almost fixes you up, but we have to do a little more. while (DATA) { my @lines = (split /\n/, $_); my %contact; for my $line (@lines) { if ($line =~ /^(\w+):\s*(.+)$/) { $contact{$1} = $2; The for loop below is in the wrong spot. Here we're processing each line of the hash, so the loop would get run once for each and every line, giving us erroneous output. We need to move it down a bit... for (keys %contact) { if (/^Name/ or /^City/ or /^State/) { Minor complaint about the line above. Don't use a Regex to test equality. Save the big guns for when you actually need pattern matching. It should read: if ($_ eq 'Name' || $_ eq 'City' || $_ eq 'State') { print $_: $contact{$_}\n; } } } } Move that for loop I mentioned above to here and add a: print \n; after the loop. That fixes your program. Let's look into it a little more though... } Putting everything I've said so far together, we get the code: #!/usr/bin/perl use warnings; use strict; local $/ = ''; while (DATA) { my @lines = (split /\n/, $_); my %contact; for my $line (@lines) { if ($line =~ /^(\w+):\s*(.+)$/) { $contact{$1} = $2; } } for (keys %contact) { if ($_ eq 'Name' || $_ eq 'City' || $_ eq 'State') { print $_: $contact{$_}\n; } } print \n; } __DATA__ Name: Bob City: Austin State: Texas Address: 123 Whatever Age: 46 Name: Jose City: Denver State: Colorado Address: 118 Mystreet Age: 28 Go ahead and paste that into a file and run it a few times for some interesting results. Do you see it? The order of the output changes with subsequent runs if you're running a fairly recent version of perl. I don't think it was ever said if order is significant in this problem, but the behavior is annoying so let's fix it too. The problem is in the output loop: for (keys %contact) { if ($_ eq 'Name' || $_ eq 'City' || $_ eq 'State') { print $_: $contact{$_}\n; } } That loop fetches all the keys of the hash and then prints the Name, City and State as it finds them. Trouble is, perl isn't guaranteed to return those keys in a set order and indeed it doesn't. The loop is also wasteful as it has to go through keys we don't care about. Let's change it to ask for what we want instead: for (qw(Name City State)) { print $_: $contact{$_}\n; } That does it. The program now returns what we expect every time it's run. Hope that clears things up for you. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Connecting to the Netware Server using ssh
Hi all, I am connecting to Netware Server using ssh 1.24 version. Here is th sample code for the same. use Net::SSH::Perl; use Net::SSH::Perl::Cipher; my $ssh = Net::SSH::Perl-new(xx.xx.xx.xx, cipher = DES, interactive = true, debug = 1); $ssh-login(username, passwd); # $ssh-login; my ($out, $in)=$ssh-open2(m xxx.nlm); ( Previously i tried cmd but my consle screen hangs and does not go forward) close $in; while ($out) { # Process output print $out; print I am here:; } close $out; i.e. in place of $ssh-cmd() i put open2() and able to run the command on the netware Server but always gettig output as empty So if you have to see the result of my command executed on the netware Server I am not able to do so as in linux box i was always getting some number generated related to success or failure. Could you please let me know if I am doing something wrong. Thanks, Amit -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: JPG FILE DOUBTS
On Fri, 16 Jan 2004, Jan Eden wrote: if (`file $file` =~ /JPEG/) { print $file appears to be a JPEG file.\n; } else { print $file does not appear to be a JPEG file.\n; } This will tell you if the filename contains a certain string. That does not make the file a valid image file (besides, there's .jpg and .jpeg, both in uppercase and lowercase, so your pattern should be: /jpe?g/i if you just want to check the name. - Jan Not true in UNIX. Maybe in Windows, I don't know. Please notice the backticks which execute the file command. The file command in Linux examines the file in the command line and sends a single line indicating its opinion of what type of file the specified file is. It actually reads the file looking for markers of some sort. If the file is a JPEG file, then the response from the file command will contain the string JPEG (in upper case), which is what I test for. This only works, as best as I know, on a UNIX system. Windows doesn't have this command, or it works differently. I don't do Windows. -- -- Maranatha! John McKown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: JPG FILE DOUBTS
On Fri, 16 Jan 2004, Jan Eden wrote: Jan Eden wrote: Sorry! Please disregard my previous post, I overlooked the backquotes. - Jan I gotta learn to read all the posts before replying to correct somebody who has already corrected themselves. Sorry about that. Well, maybe my explanation will be useful to others. grin -- -- Maranatha! John McKown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
what is this data structure?
Hi, I don't know how to work with this data structure: my @array = ((a = 'appple'), (b = 'tree'), (c = 'chair')); when I do: print @array; I get no output. when I do: use Data::Dumper; print Dumper(@array); I got the contents of it. Thanks, Jack -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
unscribe
How i can unscribe ??? __ Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l'antivirus, il filtro Anti-spam http://it.yahoo.com/mail_it/foot/?http://it.mail.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: what is this data structure?
On 1/16/2004 11:03 AM, Jack Chen wrote: Hi, I don't know how to work with this data structure: my @array = ((a = 'appple'), (b = 'tree'), (c = 'chair')); when I do: print @array; I get no output. when I do: use Data::Dumper; print Dumper(@array); I got the contents of it. Despite all of the punctuation, it is nothing more than an array. The following is equivelant: my @array = qw( a apple b tree c chair ); I find it more helpfull when using Data::Dumper to print a reference to the variable I want to examine. I.e. print Dumper([EMAIL PROTECTED]); To me it makes the structure easier to interpret. I don't understand though why you saw nothing for 'print @array', are you sure you ran the code as above. I get: print @array; = aappplebtreecchair print @array; = a appple b tree c chair Regards, Randy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: unscribe
It was Friday, January 16, 2004 when Walter Valenti took the soap box, saying: : How i can unscribe ??? : [snipping yahoo sig] : -- : To unsubscribe, e-mail: [EMAIL PROTECTED] There you are. :-) Casey West -- Shooting yourself in the foot with Windows 95 Your gun is not compatible with this OS and you must buy an upgrade and install it before you can continue. Then you will be informed that you don't have enough memory. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: unscribe
On 1/16/2004 11:43 AM, Walter Valenti wrote: How i can unscribe ??? Read the signature line in any message on the list. Send an e-mail to the appropriate address. You will be sent a confirmation email=-be sure you reply to it to complete the process. Regards, Randy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: unscribe
Surprisingly, that doesn't work. Then God said, let there be rules, so I created a rule in Outlook to delete PERL.ORG emails. Few sneak by though -Original Message- From: Casey West [mailto:[EMAIL PROTECTED] Sent: Friday, January 16, 2004 11:55 AM To: Walter Valenti Cc: [EMAIL PROTECTED] Subject: Re: unscribe It was Friday, January 16, 2004 when Walter Valenti took the soap box, saying: : How i can unscribe ??? : [snipping yahoo sig] : -- : To unsubscribe, e-mail: [EMAIL PROTECTED] There you are. :-) Casey West -- Shooting yourself in the foot with Windows 95 Your gun is not compatible with this OS and you must buy an upgrade and install it before you can continue. Then you will be informed that you don't have enough memory. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: unscribe
It was Friday, January 16, 2004 when Jilani, Mohammad K took the soap box, saying: : Surprisingly, that doesn't work. Then God said, let there be rules, so I : created a rule in Outlook to delete PERL.ORG emails. Few sneak by though Please describe doesn't work. It would be terrible if all unsubscribe requests weren't working. Casey West -- Good Idea: Dressing up for Halloween as a pirate. Bad Idea: Dressing up for Halloween as a pin~ata. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: what is this data structure?
Hi Randy, Thanks for reply! It is strage. When I tried the script on another machine, it works the way you described. Anything wrong about my perl or my OS (Linux 8)? Jack On Fri, 16 Jan 2004, Randy W. Sims wrote: On 1/16/2004 11:03 AM, Jack Chen wrote: Hi, I don't know how to work with this data structure: my @array = ((a = 'appple'), (b = 'tree'), (c = 'chair')); when I do: print @array; I get no output. when I do: use Data::Dumper; print Dumper(@array); I got the contents of it. Despite all of the punctuation, it is nothing more than an array. The following is equivelant: my @array = qw( a apple b tree c chair ); I find it more helpfull when using Data::Dumper to print a reference to the variable I want to examine. I.e. print Dumper([EMAIL PROTECTED]); To me it makes the structure easier to interpret. I don't understand though why you saw nothing for 'print @array', are you sure you ran the code as above. I get: print @array; = aappplebtreecchair print @array; = a appple b tree c chair Regards, Randy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: what is this data structure?
Jack Chen [EMAIL PROTECTED] wrote: : : I don't know how to work with this data structure: : : my @array = ((a = 'appple'), : (b = 'tree'), :(c = 'chair')); : : when I do: : : print @array; : : I get no output. It printed okay for me. Perhaps something else is wrong. Show us everything. aappplebtreecchair HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Net::Scp
I am using the code below. When I run the script if I run it for just one file then everything works fine. It asks me for my passpharase and copies perfectly. If I uncomment both scp - iscp statements and run the script it asks me for the first one and then locks on the question proceed [y/N] for the second I have to kill the cmd window to get back. Any thoughts? #!/usr/bin/perl use strict; use warnings; use Net::SCP qw / scp iscp /; my $leases = 'hylafax:/var/state/dhcp/dhcpd.leases'; my $access = 'hylafax:/usr/local/squid/var/logs/access.log'; my $scp = Net::SCP - new ( 'hylafax', 'pdk' ); print Getting Leases File\n; $scp - iscp ( $leases, 'scpleases.txt' ); print Getting Access File\n; $scp - iscp ( $access, 'scpaccess.txt' ); Paul Kraus --- PEL Supply Company Network Administrator --- 800 321-1264 Toll Free 216 267-5775 Voice 216 267-6176 Fax www.pelsupply.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: unscribe
I've tried too without any success---tried both unsubscribe approaches described in the digest: [EMAIL PROTECTED] AND [EMAIL PROTECTED] Never received any feedback messages. -Original Message- From: Casey West [mailto:[EMAIL PROTECTED] Sent: Friday, January 16, 2004 12:08 PM To: Jilani, Mohammad K Cc: '[EMAIL PROTECTED]'; Walter Valenti; [EMAIL PROTECTED] Subject: Re: unscribe It was Friday, January 16, 2004 when Jilani, Mohammad K took the soap box, saying: : Surprisingly, that doesn't work. Then God said, let there be rules, so I : created a rule in Outlook to delete PERL.ORG emails. Few sneak by though Please describe doesn't work. It would be terrible if all unsubscribe requests weren't working. Casey West -- Good Idea: Dressing up for Halloween as a pirate. Bad Idea: Dressing up for Halloween as a pin~ata. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: unscribe
It was Friday, January 16, 2004 when Smith Jeff D took the soap box, saying: : I've tried too without any success---tried both unsubscribe approaches : described in the digest: : : [EMAIL PROTECTED] AND : [EMAIL PROTECTED] : : Never received any feedback messages. That is odd. Are you certain you used the originally subscribed email address? Also, you can try the form at http://learn.perl.org. I've tested these and had success with my originally subscribed email address. Please let me know if the web form works correctly. Casey West -- Shooting yourself in the foot with MasPar You shoot all of your friends' feet simultaneously. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Data File, turn fields on mulitple lines into records on one line.. .
Rob Dixon wrote: If you set the input record separator - $/ - to a null string then it will split the input file on one or more blank lines. Take a look at the program below. #!perl use strict; use warnings; local $/ = ''; while (DATA) { my @data = split /\n/; print join(':', @data), \n; } __DATA__ Date Team Name 1 Team Name 2 Field1 Field2 FieldX Date Team Name 3 Team Name 4 Field 1 FieldX **OUTPUT Date:Team Name 1:Team Name 2:Field1:Field2:FieldX Date:Team Name 3:Team Name 4:Field 1:FieldX TMTOWTDI :-) #!/usr/bin/perl use strict; use warnings; ( $/, $\ ) = ( '', \n ); while ( DATA ) { chomp; tr/\n/:/; print; } __DATA__ Date Team Name 1 Team Name 2 Field1 Field2 FieldX Date Team Name 3 Team Name 4 Field 1 FieldX 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
AUTOLOAD error in a module
Don't know if this is the correct list.. tell me if i'm wrong! I'm doing perl bindings for a c library (gai). I've used swig with some typemaps.. It works in mine pc, but when i've sended my works to gai's author.. : perl Makefile.PL works fine, make works fine, make install works fine! but when he try to launch a simple example : ./hello-world.pl Use of inherited AUTOLOAD for non-method gai::gai_init() is deprecated at ./hello-world.pl line 9. Can't locate auto/gai/gai_init.al in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at ./hello-world.pl line 9 mmm what is this? if you want i can send Makefile.PM and gai.pm hi! Luca -- Even more amazing was the realization that God has Internet access. I wonder if He has a full newsfeed? (By Matt Welsh) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: the file is there.. I know it is.
Chad Kellerman wrote: Hello everyone, Hello, I am starting to work on a script that is going to process a few files in some users directories. I thought I would do some checking on the file to make sure they are there and to make sure they are really files. I thought it was going to be pretty straight forward, until I ran it for the first time. Sometimes the script sees the file for one user but not the next ( that I know is there)? I must be misunderstanding something small, but I can't figure it out. Can anyone offer any suggestions? Certainly. #!/usr/local/bin/perl eval 'exec /usr/local/bin/perl -S $0 ${1+$@}' if 0; #$running_under_some_shell Do you really need those two lines? use strict; use warnings; use Sys::Hostname; $|++; use vars qw( $server $pwdfile @users ); In most modern Perls you would use our() instead of use vars. our ( $server, $pwdfile, @users ); $server = hostname(); $pwdfile = '/etc/passwd'; Most Perl programmers advocate declaring and defining your variables at the same time. our $server = hostname(); our $pwdfile = '/etc/passwd'; # get users open (PASSWD,$pwdfile) or die Cannot open passwd file: $!; while (my $pwdline = PASSWD) Perl provides a built-in function getpwent() that reads from the password file and also the User::pwent module. { my ($user,$home,$shell) = (split /:/, $pwdline)[0,5,6]; next if ( $home !~ /^\/home/ || $shell !~ /^\/bin/ || $user eq ftp || $user eq www); push @users, $user; } close (PASSWD); foreach my $user(@users) { print Starting $user...\n; #print glob (/home/$user/*-logs/old/200312/access-log.31-*.gz).\n; $user = trim($user); You are modifying the user entry returned from the passwd file. Are you sure you want to do that? (Hint: probably not.) my $decfile = glob (/home/$user/*-logs/old/200312/access-log.31-*.gz); my $janfile = glob (/home/$user/*-logs/old/200401/access-log.01-*.gz); if (!$decfile) { print \t\\Could not find Dec 31,2003 access log.\n; next; } elsif (!-f $decfile) { print \t\\Dec 31,2003 access log is not a file.\n; next; } elsif (!$janfile) { print \t\\Could not find Jan 01,2004 access log.\n; next; } elsif (!-f $janfile) { print \t\\Jan 01,2004 access log is not a file.\n; next; } else { print \t\\$user has both access logs.\n; } You can simplify that a bit: my @files = grep -f, glob /home/$user/*-logs/old/{200312,200401}/access-log.{31,01}-*.gz; print \t\\$user has both access logs.\n if @files == 2; } # subs sub trim { my @in = @_; for (@in) { s/^\s+//; s/\s+$//; s/\n//g; } return wantarray ? @in : $in[0]; } 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: the file is there.. I know it is.
Paul Johnson wrote: chad kellerman said: I am starting to work on a script that is going to process a few files in some users directories. I thought I would do some checking on the file to make sure they are there and to make sure they are really files. I thought it was going to be pretty straight forward, until I ran it for the first time. Sometimes the script sees the file for one user but not the next ( that I know is there)? I must be misunderstanding something small, but I can't figure it out. Can anyone offer any suggestions? You are using glob in a scalar context. This is not what you want. perldoc -f glob Interestingly enough it works on my system. Scalar and list context both return the first file name from the glob. 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: Data File, turn fields on mulitple lines into records on one li ne.. .
Taylor Lewick wrote: One more for everyone... In my perl script, I did a quick cheat by using the systems grep command... I tried: `/usr/bin/grep -v BLAH | /usr/bin/grep -v COW | /usr/bin/grep -v STUFF file1file2`; And this doesn't work. Sometimes it will get rid of STUFF. It seems to only act on the last grep I use. I tried escaping the pipes, but that didn't work. Any ideas? Yes, you have the file name in the wrong place. The syntax is do something to FILE | pipe data to second process | pipe data to third process redirect STDOUT to a file. What you have is do something to STDIN | pipe data to second process | pipe data to third process but use FILE instead redirect STDOUT to a file. You have to specify the file name on the first process in the pipeline. 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
check protocol
Hello, we have an affiliate system where affiliates put links on their websites, and we need to make sure they are using the https:// protocol when the customer clicks on the link, IE: https://www.ourdomain.com/cgi-bin/script.cgi?somequery_stringhere is there an effective way to make sure, before the script process the request, that it can check that it was called via the https and not http protocal ?? TIA ;) -- MikemickaloBlezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! http://www.thunder-rain.com Quality Web Hosting http://www.justlightening.net MSN: [EMAIL PROTECTED] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: check protocol
Hello, we have an affiliate system where affiliates put links on their websites, and we need to make sure they are using the https:// protocol when the customer clicks on the link, IE: https://www.ourdomain.com/cgi-bin/script.cgi?somequery_stringhere is there an effective way to make sure, before the script process the request, that it can check that it was called via the https and not http protocal ?? TIA ;) To me the easiest way to handle this would be to configure a distinct cgi-bin for the port (presumably 443) that the secure scripts run under. At that point if they can be run, they must be on a secure channel. Barring the ability to do that, you should be able to check the port that the request was made on based on the environment setup by the web server assuming it matches your secure port, then the request was made properly. I assume you are worried about the response information rather than the request, in the latter case there is little reason to check in a server side script whether the client has requested it over a secure channel, as the whole point of the security at that point is moot, I suppose in the latter case it would still make sense if you were pushing them secure information. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Data File, turn fields on mulitple lines into records on one li ne.. .
Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Data File, turn fields on mulitple lines into records on one li ne.. .
Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? What is the real goal? Aka why are you shelling out to grep in the first place? As a side note you should be using full paths for grep, file1, file2, and you should be checking the return code of the command. Also it seems silly to use backticks if you are piping STDOUT to a file. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: check protocol
Thx's after reading your post,... it then dawned on me the ever-handy CGI.pm has the server_port() function that will do what I need :) thx's again for the help, -- MikemickaloBlezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! http://www.thunder-rain.com Quality Web Hosting http://www.justlightening.net MSN: [EMAIL PROTECTED] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Wiggins d Anconia wrote: Hello, we have an affiliate system where affiliates put links on their websites, and we need to make sure they are using the https:// protocol when the customer clicks on the link, IE: https://www.ourdomain.com/cgi-bin/script.cgi?somequery_stringhere is there an effective way to make sure, before the script process the request, that it can check that it was called via the https and not http protocal ?? TIA ;) To me the easiest way to handle this would be to configure a distinct cgi-bin for the port (presumably 443) that the secure scripts run under. At that point if they can be run, they must be on a secure channel. Barring the ability to do that, you should be able to check the port that the request was made on based on the environment setup by the web server assuming it matches your secure port, then the request was made properly. I assume you are worried about the response information rather than the request, in the latter case there is little reason to check in a server side script whether the client has requested it over a secure channel, as the whole point of the security at that point is moot, I suppose in the latter case it would still make sense if you were pushing them secure information. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Data File, turn fields on mulitple lines into records on one li ne.. .
Taylor Lewick wrote: Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; Is that what the ACTUAL line looks like? (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? Use perl to do it: open my $in, '', 'file1' or die Cannot open file1: $!; open my $out, '', 'file2' or die Cannot open file2: $!; while ( $in ) { next if /STUFF:STUFF/; print $out; } close $out; close $in; 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: Data File, turn fields on mulitple lines into records on one li ne.. .
So you recommend using regular expressions instead of grep..? Care to provide an example in this case? -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, January 16, 2004 3:16 PM To: Lewick, Taylor; [EMAIL PROTECTED] Subject: RE: Data File, turn fields on mulitple lines into records on one li ne.. . Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? What is the real goal? Aka why are you shelling out to grep in the first place? As a side note you should be using full paths for grep, file1, file2, and you should be checking the return code of the command. Also it seems silly to use backticks if you are piping STDOUT to a file. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Data File, turn fields on mulitple lines into records on one li ne.. .
Okay, will do... One more, what about a sed command that deletes the first 3 spaces of each line... i.e., how would I do this in perl... sed 's/^ //' file1 file2 -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Friday, January 16, 2004 3:24 PM To: [EMAIL PROTECTED] Subject: Re: Data File, turn fields on mulitple lines into records on one li ne.. . Taylor Lewick wrote: Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; Is that what the ACTUAL line looks like? (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? Use perl to do it: open my $in, '', 'file1' or die Cannot open file1: $!; open my $out, '', 'file2' or die Cannot open file2: $!; while ( $in ) { next if /STUFF:STUFF/; print $out; } close $out; close $in; 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
RE: Data File, turn fields on mulitple lines into records on one li ne.. .
Please bottom post... So you recommend using regular expressions instead of grep..? Care to provide an example in this case? John just provided a good one. Optionally if all you care about is determining whether a line contains a string it might (I didn't benchmark it) be faster to use 'index' instead of a regex: perldoc -f index My complaint is about the use of shelling out to handle something that can be easily done programmatically within Perl itself, aka like John showed using two opens and a simple while with the diamond operator (and conveniently it has more error checking in it, should be faster, is more secure, less error prone, and portable!). To me shelling out is a last resort, or a quick fix (aka if you have to ask here it isn't quick enough). http://danconia.org -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, January 16, 2004 3:16 PM To: Lewick, Taylor; [EMAIL PROTECTED] Subject: RE: Data File, turn fields on mulitple lines into records on one li ne.. . Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? What is the real goal? Aka why are you shelling out to grep in the first place? As a side note you should be using full paths for grep, file1, file2, and you should be checking the return code of the command. Also it seems silly to use backticks if you are piping STDOUT to a file. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Creating My Own Escapes
I have a problem I just cant seem to get my head around, so any help is appreciated. I have a string. It could contain anything a Perl string can contain. I have to print this string to a file and later bring it back in exactly as it was. However, because of the file format, the string in the file may not contain \n characters. That's the only difference between the two representations of this string. Okay, obviously I need to replace all \n characters. Let's say I want to follow Perl's example and use a literal \ followed by a literal n. Then I would also need to escape \ characters. Okay, again we'll use Perl's \ and another \. Does that cover everything if \n is the only illegal character in my file format? I believe, so, but please correct me if I'm wrong. The to file conversion seems simple given the above: $string =~ s/\\//g; $string =~ s/\n/\\n/g; Does that work as good as I think it does? Now I have to get it back out of the file and that's where it falls apart on me. I've tried things like: $string =~ s/((?:^|[^\\])(?:)*)\\n/$1\n/g; $string =~ s//\\/g; While that gets close, it doesn't seem to work on everything. Here's an example (one-liner reformatted for easier reading): perl -e ' $test = \tFunky \Stringn\n; print String: $test\n; $test =~ s/\\//g; $test =~ s/\n/\\n/g; print To File: $test\n; $test =~ s/((?:^|[^\\])(?:)*)\\n/$1\n/g; $test =~ s//\\/g; print From File: $test\n ' String: Funky String\ To File:Funky String\\\n\n From File: Funky String\ \n Any advice is appreciated. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
perl grep..
John thank you for the example, one question about the example code... It isn't printing anything to my out file, although it does create it. On the print $out line, I don't need print $out $_\n; do I? Or, the expression /STUFF:STUFF/ What if my line looks like this.. 1 17 7 PM ET:Name:Name:STUFF:STUFF:STUFF Would the example you provided still match this line? I suspect this is the issue but am not sure. Would I need something like /.*STUFF:STUFF/ ? Thanks again, Taylor -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Creating My Own Escapes
At 01:38 PM 1/16/2004, James Edward Gray II wrote: I have a problem I just cant seem to get my head around, so any help is appreciated. I have a string. It could contain anything a Perl string can contain. I have to print this string to a file and later bring it back in exactly as it was. However, because of the file format, the string in the file may not contain \n characters. That's the only difference between the two representations of this string. Okay, obviously I need to replace all \n characters. Let's say I want to follow Perl's example and use a literal \ followed by a literal n. Then I would also need to escape \ characters. Okay, again we'll use Perl's \ and another \. Does that cover everything if \n is the only illegal character in my file format? I believe, so, but please correct me if I'm wrong. The to file conversion seems simple given the above: $string =~ s/\\//g; $string =~ s/\n/\\n/g; Does that work as good as I think it does? Now I have to get it back out of the file and that's where it falls apart on me. I've tried things like: $string =~ s/((?:^|[^\\])(?:)*)\\n/$1\n/g; $string =~ s//\\/g; While that gets close, it doesn't seem to work on everything. Here's an example (one-liner reformatted for easier reading): perl -e ' $test = \tFunky \Stringn\n; print String: $test\n; $test =~ s/\\//g; $test =~ s/\n/\\n/g; print To File: $test\n; $test =~ s/((?:^|[^\\])(?:)*)\\n/$1\n/g; $test =~ s//\\/g; print From File: $test\n ' String: Funky String\ To File:Funky String\\\n\n From File: Funky String\ \n Any advice is appreciated. I just had to do something like this yesterday, and I couldn't figure out how to do it in just one regex, but I did find a way that you could use. I have a database giving me single and double quotes in variables as their octal equivalent. I get a variable from the database as: Dan\047s \042Baby\042 and I need the variable converted back to: Dan's Baby So, I did the following, @words is a list of variables to convert # change octal \0nn to the appropriate character foreach (@words) { while ($_ =~ /\\(0\d{2})/) { my $myChar = chr(oct $1); $_ =~ s/\\$1/$myChar/g; } } This works, but I am sure there is a better way to code this, and I was thinking of asking that when I had time. To use it, instead of coverting newlines to \n, convert them to \012. -Mark -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Creating My Own Escapes
On Jan 16, 2004, at 3:38 PM, James Edward Gray II wrote: Now I have to get it back out of the file and that's where it falls apart on me. I've tried things like: $string =~ s/((?:^|[^\\])(?:)*)\\n/$1\n/g; $string =~ s//\\/g; Sorry to reply to my own post, but does this work? It seems to in all the test cases I can dream up: $string =~ s/\\([n\\])/$1 eq \\ ? $1 : \n/ge; James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Creating My Own Escapes
On Jan 16, 2004, at 4:22 PM, Mark LoBue wrote: I just had to do something like this yesterday, and I couldn't figure out how to do it in just one regex, but I did find a way that you could use. I have a database giving me single and double quotes in variables as their octal equivalent. I get a variable from the database as: Dan\047s \042Baby\042 and I need the variable converted back to: Dan's Baby So, I did the following, @words is a list of variables to convert # change octal \0nn to the appropriate character foreach (@words) { while ($_ =~ /\\(0\d{2})/) { my $myChar = chr(oct $1); $_ =~ s/\\$1/$myChar/g; } } This works, but I am sure there is a better way to code this, and I was thinking of asking that when I had time. To use it, instead of coverting newlines to \n, convert them to \012. Thanks for the suggestion. I'm mostly concerned about the interaction of \\ and \n in pathological cases like the string \\\n\n\\n. Which one do I convert first? laughs Since you're helping me, I'll give you a tip. The above loop is the same as: s/\\(0\d\d)/chr(oct $1)/ge foreach @words; Thanks again. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Creating My Own Escapes
On Fri, Jan 16, 2004 at 03:38:40PM -0600 James Edward Gray II wrote: I have a problem I just cant seem to get my head around, so any help is appreciated. I have a string. It could contain anything a Perl string can contain. I have to print this string to a file and later bring it back in exactly as it was. However, because of the file format, the string in the file may not contain \n characters. That's the only difference between the two representations of this string. Okay, obviously I need to replace all \n characters. Let's say I want to follow Perl's example and use a literal \ followed by a literal n. Then I would also need to escape \ characters. Okay, again we'll use Perl's \ and another \. Does that cover everything if \n is the only illegal character in my file format? I believe, so, but please correct me if I'm wrong. Maybe B::perlstring() will do what you need: [EMAIL PROTECTED]:~$ perl -lMB=perlstring -e '$var = \n\r\f; print perlstring( $var bla\\\ \n )' \n\r\f bla\\\ \n Tassilo -- $_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Data File, turn fields on mulitple lines into records on one li ne.. .
Taylor Lewick wrote: From: John W. Krahn [mailto:[EMAIL PROTECTED] Taylor Lewick wrote: Okay, I redid it so it looks like this... `grep -v STUFF:STUFF file1 file2`; Is that what the ACTUAL line looks like? (I am looking for the string STUFF:STUFF and that didn't work... but it works via command line... Any ideas? Use perl to do it: open my $in, '', 'file1' or die Cannot open file1: $!; open my $out, '', 'file2' or die Cannot open file2: $!; while ( $in ) { next if /STUFF:STUFF/; print $out; } close $out; close $in; Okay, will do... One more, what about a sed command that deletes the first 3 spaces of each line... i.e., how would I do this in perl... sed 's/^ //' file1 file2 open my $in, '', 'file1' or die Cannot open file1: $!; open my $out, '', 'file2' or die Cannot open file2: $!; while ( $in ) { s/^ //; print $out; } close $out; close $in; 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: Data File, turn fields on mulitple lines into records on one line.. .
John W. Krahn wrote: TMTOWTDI :-) #!/usr/bin/perl use strict; use warnings; ( $/, $\ ) = ( '', \n ); while ( DATA ) { chomp; tr/\n/:/; print; } Rogue! /R -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: perl grep..
Taylor Lewick wrote: John thank you for the example, one question about the example code... It isn't printing anything to my out file, although it does create it. On the print $out line, I don't need print $out $_\n; do I? I didn't remove the \n character from the input line so it doesn't have to be added to the output line and print() prints the contents of $_ if nothing other than the filehandle is passed to it. Or, the expression /STUFF:STUFF/ What if my line looks like this.. 1 17 7 PM ET:Name:Name:STUFF:STUFF:STUFF Would the example you provided still match this line? I suspect this is the issue but am not sure. What EXACTLY is STUFF? It could contain regex meta-characters which will cause it to fail. Maybe you should use index() instead (as Wiggins suggested.) Would I need something like /.*STUFF:STUFF/ ? No. 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: Creating My Own Escapes
James Edward Gray II wrote: I have a problem I just cant seem to get my head around, so any help is appreciated. I have a string. It could contain anything a Perl string can contain. I have to print this string to a file and later bring it back in exactly as it was. However, because of the file format, the string in the file may not contain \n characters. That's the only difference between the two representations of this string. Okay, obviously I need to replace all \n characters. Let's say I want to follow Perl's example and use a literal \ followed by a literal n. Then I would also need to escape \ characters. Okay, again we'll use Perl's \ and another \. Does that cover everything if \n is the only illegal character in my file format? I believe, so, but please correct me if I'm wrong. The to file conversion seems simple given the above: $string =~ s/\\//g; $string =~ s/\n/\\n/g; Does that work as good as I think it does? see if the following works better: #!/usr/bin/perl -w use strict; my $o = my $s = Funky \St\nringn\n\n\n\n\n\n\n; $s =~ s.\n.\\n.g; $s =~ s.\\(?!n)..g; print After encode: $s\n; $s =~ s.\\n.\n.g; $s =~ s..\\.g; print they are ,$o eq $s ? :not ,same\n; __END__ prints: After encode: Funky St\nring\\\n\n\n\n\n\n\n\n they are same if the regx doesn't cover all cases, please post a few exceptions. david -- sub'_{print@_ ;* \ = * __ ,\ \} sub'__{print@_ ;* \ = * ___ ,\ \} sub'___{print@_ ;* \ = * ,\ \} sub'{print@_,\n}{_+Just}(another)-(Perl)-(Hacker) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: the file is there.. I know it is.
On Fri, Jan 16, 2004 at 11:47:59AM -0800, John W. Krahn wrote: Paul Johnson wrote: chad kellerman said: I am starting to work on a script that is going to process a few files in some users directories. I thought I would do some checking on the file to make sure they are there and to make sure they are really files. I thought it was going to be pretty straight forward, until I ran it for the first time. Sometimes the script sees the file for one user but not the next ( that I know is there)? I must be misunderstanding something small, but I can't figure it out. Can anyone offer any suggestions? You are using glob in a scalar context. This is not what you want. perldoc -f glob Interestingly enough it works on my system. Scalar and list context both return the first file name from the glob. Right, the first time round the loop. But the behaviour is different the next time, as chad originally reported. $ cat globtest #!/bin/perl -l mkdir tst; chdir tst; open F, tst1; close F; print scalar glob * for 1..4; printglob * for 1..4; $ perl globtest tst1 tst1 tst1 tst1 tst1 tst1 $ -- 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
Redirect stdout, stderr to file and stdout
I have a small script that does some admin work for me. What I need to do now is not only have is display information to STDERR and STDOUT but also write the same information I see when I run the command to a file. I have written it for others who are not very technical. I want them to be able to see the script working and what it is doing. But I also need a log file of the same information so I can have it mailed to me and keep a copy on the server. I cant seem to get this to work. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Redirect stdout, stderr to file and stdout
On Jan 16, 2004, at 5:02 PM, Larry Guest wrote: I have a small script that does some admin work for me. What I need to do now is not only have is display information to STDERR and STDOUT but also write the same information I see when I run the command to a file. I have written it for others who are not very technical. I want them to be able to see the script working and what it is doing. But I also need a log file of the same information so I can have it mailed to me and keep a copy on the server. Here's a bit of a wacky Idea - solve it by a bit of indirection - namely write the code so that it does what you want it to do then nest it inside of a script like say #!/bin/sh myPerlCode 21 | tee /tmp/myOutput.$$ mail me -s command run /tmp/myOutput.$$ /bin/rm -f /tmp/myOutput.$$ that way your perl code remains simple, but what you hand out to the users to use is going to deal with all of the STDOUT|STDERR as well a always sending you the email... ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Redirect stdout, stderr to file and stdout
One quick and dirty solution that I've used for some debugging in the past is to create a subroutine called PrintOut(); ### use strict; use warnings; open(OUTFILE,mylog.txt) || die; PrintOut(Hello World\n); sub PrintOut{ print @_; print OUTFILE @_; } ### -Original Message- From: Larry Guest [mailto:[EMAIL PROTECTED] Sent: Friday, January 16, 2004 5:03 PM To: [EMAIL PROTECTED] Subject: Redirect stdout, stderr to file and stdout What I need to do now is not only have is display information to STDERR and STDOUT but also write the same information I see when I run the command to a file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Redirect stdout, stderr to file and stdout
On Fri, Jan 16, 2004 at 05:02:52PM -0800, Larry Guest wrote: I have a small script that does some admin work for me. What I need to do now is not only have is display information to STDERR and STDOUT but also write the same information I see when I run the command to a file. I have written it for others who are not very technical. I want them to be able to see the script working and what it is doing. But I also need a log file of the same information so I can have it mailed to me and keep a copy on the server. I cant seem to get this to work. You don't say what OS you are on, but on *nix I would do something like: $ perl -le 'print STDERR stderr; print stdout' 21 | tee output.txt Solutions in Perl take more effort, but we can discuss them if necessary. -- 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
Re: Creating My Own Escapes
On Jan 16, 2004, at 4:43 PM, Tassilo von Parseval wrote: Maybe B::perlstring() will do what you need: [EMAIL PROTECTED]:~$ perl -lMB=perlstring -e '$var = \n\r\f; print perlstring( $var bla\\\ \n )' \n\r\f bla\\\ \n I didn't know about that subroutine. Thank you very much! James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Redirect stdout, stderr to file and stdout
On Fri, 16 Jan 2004, Larry Guest wrote: I have a small script that does some admin work for me. What I need to do now is not only have is display information to STDERR and STDOUT but also write the same information I see when I run the command to a file. I have written it for others who are not very technical. I want them to be able to see the script working and what it is doing. But I also need a log file of the same information so I can have it mailed to me and keep a copy on the server. I cant seem to get this to work. What have you tried? I would alter the script to have multiple print statements. One to STDERR or STDOUT, the other to my file. Something like: open(LOGGER,'myfile.log'); ... print STDERR $message\n; print LOGGER $message\n; ... If you want, you could encapsulate this by not using print directly, but in your own function, say myprint(). sub myprint { my $fn = shift; print $fn @_; print LOGGER @_; } my $STDOUT=\STDOUT; my $STDERR=\STDERR; ... my $message=This is a test.\n; ... myprint($STDOUT,$message); ... myprint($STDERR,$message); Hope this is useful in some way. -- Maranatha! John McKown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: the file is there.. I know it is.
Paul Johnson wrote: On Fri, Jan 16, 2004 at 11:47:59AM -0800, John W. Krahn wrote: Paul Johnson wrote: chad kellerman said: I am starting to work on a script that is going to process a few files in some users directories. I thought I would do some checking on the file to make sure they are there and to make sure they are really files. I thought it was going to be pretty straight forward, until I ran it for the first time. Sometimes the script sees the file for one user but not the next ( that I know is there)? I must be misunderstanding something small, but I can't figure it out. Can anyone offer any suggestions? You are using glob in a scalar context. This is not what you want. perldoc -f glob Interestingly enough it works on my system. Scalar and list context both return the first file name from the glob. Right, the first time round the loop. But the behaviour is different the next time, as chad originally reported. Yes. This is documented in perlop.pod. perldoc perlop [snip] A (file)glob evaluates its (embedded) argument only when it is starting a new list. All values must be read before it will start over. In list context, this isn't important because you automatically get them all anyway. However, in scalar context the operator returns the next value each time it's called, or C run out. As with filehandle reads, an automatic `defined' is generated when the glob occurs in the test part of a `while', because legal glob returns (e.g. a file called 0) would otherwise terminate the loop. Again, `undef' is returned only once. So if you're expecting a single value from a glob, it is much better to say ($file) = blurch*; than $file = blurch*; because the latter will alternate between returning a filename and returning false. 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