CGI Script to annoy script kiddies.
I just put together this script to annoy script kiddies looking for cmd.exe on my Linux-based web server. Just wanted to know what people thought about its security. AFAIK, it's pretty safe. Also, new commands and responses are appreciated. - Carl #!/usr/bin/perl -T # # Written by Carl Fischer [EMAIL PROTECTED] # # GNU license. # # This is a web server CGI designed to pretend to be cmd.exe # I'm not an expert in perl scripting security, so no guarantees as to its # safety. I think it's pretty safe though. # print Content-type: text/plain\n\n; if (defined $ARGV[0] == FALSE) { # This flushes STDOUT after every command (I hope). $|=1; # if no argument is given, make it look like we've hung at C:\ print EOF Microsoft(R) Windows NT(TM) (C) Copyright 1985-1996 Microsoft Corp. EOF ; print 'C:\ '; sleep 30; } else { if ($ARGV[0] =~ /\/c/i) { # Handle those obnoxious dir requests. if ($ARGV[1] eq 'dir') { $dir = 'C:\\'; # If any other path to dir is specified, say we can't find it. unless ( (defined $ARGV[2] == FALSE) || ($ARGV[2] =~ /^C:.?$/i) ) { if ($ARGV[2] =~ /[ABD-Gabd-g]:/) { print The device is not ready\n; } else { print The system cannot find the file specified.\n\n; } } else { # if no path is given, produce this output. print EOF Volume in drive C is BAIT Volume Serial Number is A33B-666A Directory of $dir 06/02/01 12:02pDIR WINNT 09/23/03 12:43pDIR pdf995 06/02/01 12:04pDIR Program Files 06/02/01 12:05p 0 CONFIG.SYS 06/02/01 12:05p 0 AUTOEXEC.BAT 06/02/01 12:38pDIR Windows Update Setup Files 09/23/03 02:03pDIR My Documents 01/16/04 04:26a 333 GatorPdpPlg.log 09/17/03 11:57pDIR Users 09/19/03 02:33pDIR My Downloads 06/02/01 05:57p 0 temp.ps 02/03/04 02:14p 278,921,216 pagefile.sys 09/11/01 04:45pDIR My Music 02-05-04 8:30a 0 You Are a LUSER now go away.txt 14 File(s) 2,138,598 bytes 20,101,311,488 bytes free EOF ; } } elsif ($ARGV[1] eq 'type' ) { # the next logical thing to do is type a file. if (defined $ARGV[2]) { print The system cannot find the file specified\n; } else { print The syntax of the command is incorrect.\n; } } elsif ($ARGV[1] eq 'copy' ) { if (defined $ARGV[3]) { print 1 file(s) copied.\n\n; } else { print The syntax of the command is incorrect.\n; } } elsif ($ARGV[1] eq 'tftp') { print Sorry. Haven't implemented bullshit response for tftp yet.\n; } elsif ($ARGV[1] eq 'echo') { print $ARGV[2].\n unless ( join(' ', @ARGV) =~ // ); } elsif ($ARGV[1] eq 'move' ) { print 1 file(s) moved.\n\n; } elsif ($ARGV[1] eq 'del' ) { print You're one nasty little son of a bitch, aren't you?!\n; print I think I'll just keep those files.\n; print Now, go play with someone else's web server\n\n; } # If we haven't thought of it, it's a bad command. else { print EOF The name specified is not recognized as an internal or external command, operable program or batch file. EOF ; } } elsif ($ARGV[0] eq '/?') { print 'EOF' Starts a new instance of the Windows/NT command interpreter CMD [/X | /Y] [/A | /U] [/Q] [[/C | /K] string] /C Carries out the command specified by string and then terminates /K Carries out the command specified by string but remains /Q Turns the echo off /A Causes the output of internal commands to a pipe or file to be ANSI /U Causes the output of internal commands to a pipe or file to be Unicode /T:fg Sets the foreground/background colors (see COLOR /? for more info) /X Enable extensions to the Windows NT version of CMD.EXE /Y Disable extensions to the Windows NT version of CMD.EXE Note that multiple commands separated by the command separator '' are accepted for string if surrounded by quotes Command Extensions are enabled by default. You may also disable extensions for all invocations of the command processor by setting the following value in the registry to 0 HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions The command extensions involve changes and/or additions to the following commands: DEL or ERASE COLOR CD or CHDIR MD or MKDIR PROMPT PUSHD POPD SET SETLOCAL ENDLOCAL IF FOR CALL SHIFT GOTO START (also includes changes to external command invocation) ASSOC FTYPE To get specific details, type HELP commandname to view the specifics. EOF ; } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL
Re: CGI Script to annoy script kiddies.
Personally I would leave hassling script kiddies to the script kiddies To me this is a bandwidth drain. Script kiddies are an ignorant nuisance, the more time you spend on them the more they have won in their little game. http://danconia.org NICE!!! I really like this! I'm not sure about security - but it seems fairly safe, since no real system interaction is implemented... nice, real nice script - I'll have some fun with it ;) BUT, the logs will grow... On Thu, 5 Feb 2004 15:46:55 -0500 Carl Fischer [EMAIL PROTECTED] wrote: I just put together this script to annoy script kiddies looking for cmd.exe on my Linux-based web server. Just wanted to know what people thought about its security. AFAIK, it's pretty safe. Also, new commands and responses are appreciated. - Carl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: CGI Script to annoy script kiddies.
Carl == Carl Fischer [EMAIL PROTECTED] writes: Carl if (defined $ARGV[0] == FALSE) { What do you expect this to do? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
my in the perl syntax
Well I am very new to Perl. I have read Oreily's Camel book, but haven't found any thing about my that is used in any of the code. e.g my $var What is my supposed to be over here? Yahoo! India Mobile: Download the latest polyphonic ringtones. Go to http://in.mobile.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
Bouncing mails
Al Kaibala DO YOU READ THIS? List members, As administrator of the Linux SIG List, I am getting bounces for mail addressed to [EMAIL PROTECTED] I have sent Al a e-mail previously, but no response. If you look at the headers below, it appears to be coming from ta-1-28 which is Al's IP address. So if anyone sees him, ask him to check out his machine. Received: from supreme.pcug.org.au (localhost [127.0.0.1]) by pcug.org.au (8.12.9/8.12.9/TIP-2.36) with ESMTP id i16682c9013769for [EMAIL PROTECTED]; Fri, 6 Feb 2004 17:08:02 +1100 (EST) Received: from server.local (ta-1-28.tip.net.au [203.11.71.28]) by pcug.org.au (8.12.9/8.12.9/TIP-2.36) with ESMTP id i1667Ec9013610for [EMAIL PROTECTED]; Fri, 6 Feb 2004 17:07:14 +1100 (EST) -- Owen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Bouncing mails
On Fri, 6 Feb 2004 18:59:13 +1100 Owen [EMAIL PROTECTED] wrote: Al Kaibala DO YOU READ THIS? List members, My apologies, senility setting in. -- Owen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Remote script execution
Hi there, Hello Friends, I would be really grateful if someone could help me out with this. I want to write a script that when executed will get lots of details from 10 different Unix(AIX) and Windows(XP) boxes and generate a report. Sorry if this has already been mentioned (I didn't get the original message), but if what you want to do is have some degree of interaction in the remote machine you might want to consider Perl-Expect : http://sourceforge.net/projects/expectperl I actually use it for a very similar task as yours, running periodically to obtain data (ram, hard disk space, etc) on a large number of machines in our institute. (It can do for you so much more than just this, but this is also possible). Cheers, Angel de Vicente -- -- http://www.iac.es/galeria/angelv/ PostDoc Software Support Instituto de Astrofisica de Canarias -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: (U) What are the best Perl books out there ... More than 1 is fin e ... list as many as you like
Hello, If you've no experience whatsoever, then Beginning Perl for Bioinformatics is very helpful - then move on to Learning Perl I guess. It assumes no prior knowledge, and although its focus is on Biology, it's all just data isn't it? Cheers, Harvey --- On 2/4/2004 10:17 PM, wolf blaum wrote: Hi, I like: Learning Perl by Randal Schwartz Tom Phoenix as a good introduction with tons of further references Programing Perl by Larry Wall, Tom Christiansen and Jon Orwant as the ultimate refernce and pillow Mastering Perl/Tk by Steve Lidie and Nancy Walsh for times when I dont have access to this mailing list and zentaras hints The Perl Cookbook by Tom Christiansen and Nathan Torkington for when I was to lasy to think for myself (or wanted to get depressed by how much better one could solve the problem Ive been working on in hunderts of lines) And even though I never read it in the linear way: Mastering regular expressions by Jeffrey Friedl Not to forget: perldoc perltoc or www.perldoc.com and The Hitchhickers Guide to the Galaxy and Last Chance to see by Douglas Adams. I guess others would recomend The Lord of the rings too. Good night:-) Wolf Since there was no mention what kind of perl books (beginner, etc.): I'd add: Object Oriented Perl by Damian Conway, I've also been wanting to check out Learning Perl Objects, References, Modules by Randall Schwartz. Advanced Perl Programming by Sriram Srinivasan (getting slightly out of date; seems I heard of updated edition coming ???). Effective Perl Programming by Joseph Hall is not bad. Writing Perl Modules for CPAN by Sam Tregar is pretty good if your going to write modules for CPAN. Extending Embedding Perl by Tim Jenness Simon Cozens is good if your going to get into Perl/XS. You'll definately want the Perl Cookbook mentioned above. It's the Perl equivelant of the Effective C++ books. 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 Harvey Kelly mailto:[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
Perl, Tk, and RPMS
Hi folks. I run a number of RH7.3 boxes which I keep up to date using Redhat's RPMS. I've just bought Mastering Perl/Tk and need to install Tk from CPAN. However, when I try to install Tk it says that I need to have at least Perl v5.7, but the latest RH RPMS are 5.6.1. Is it possible to install Tk on top of this version of Perl? If not, how's the best way to update Perl while causing the minimal effect on my machines (I know previously, I've had problems with modules no longer working and future RPM updates causing problems). -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Search Replace in multiple files
Hi, I have to search and replace 'foo' to 'bar' in all the files in a directory(has subdirectories). The files are about 40k in size. On the command line I would do it as, find ./mydir/ -type f -print | xargs perl -pi -e 's/foo/bar/' No backup of the original files required.I am brave. What is the most efficient way to implement this inside a perl program ? There are about 30 files to be processed. I went through perldoc perlrun and saw the code. I thought it as a criminal waste of time to try and modify that code for my purpose, when I can ask you folks :-) TIA, Chetak PS: I see this term 'foo' 'bar' in many programming books, what is the etymology of this? Confidentiality Notice The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender at Wipro or [EMAIL PROTECTED] immediately and destroy all copies of this message and any attachments. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: my in the perl syntax
There is definitely an explanation in the Camel (Chapter 4.8.1, Scoped variable declarations). my $var declares a lexical variable, i.e. a variable with limited scope (where the scope is limited by an enclosing block, such as a subroutine, a conditional loop etc.). HTH, Jan Harshal Borade wrote: Well I am very new to Perl. I have read Oreily's Camel book, but haven't found any thing about my that is used in any of the code. e.g my $var What is my supposed to be over here? -- Common sense is what tells you that the world is flat. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: (U) What are the best Perl books out there ... More than 1 is fin e ... list as many as you like
Hi all, sorry i think its the otherway around. first one should know the technical basics of Perl language then dive into books like 'Beginning Perl for Bioinformatics'. As far as i have seen people who have learnt Perl language initially and then read books like those fared far better than people who took those books without knowing what Perl language is. regards, KM --- On Fri, Feb 06, 2004 at 12:08:21PM -, Harvey Kelly wrote: Hello, If you've no experience whatsoever, then Beginning Perl for Bioinformatics is very helpful - then move on to Learning Perl I guess. It assumes no prior knowledge, and although its focus is on Biology, it's all just data isn't it? Cheers, Harvey --- On 2/4/2004 10:17 PM, wolf blaum wrote: Hi, I like: Learning Perl by Randal Schwartz Tom Phoenix as a good introduction with tons of further references Programing Perl by Larry Wall, Tom Christiansen and Jon Orwant as the ultimate refernce and pillow Mastering Perl/Tk by Steve Lidie and Nancy Walsh for times when I dont have access to this mailing list and zentaras hints The Perl Cookbook by Tom Christiansen and Nathan Torkington for when I was to lasy to think for myself (or wanted to get depressed by how much better one could solve the problem Ive been working on in hunderts of lines) And even though I never read it in the linear way: Mastering regular expressions by Jeffrey Friedl Not to forget: perldoc perltoc or www.perldoc.com and The Hitchhickers Guide to the Galaxy and Last Chance to see by Douglas Adams. I guess others would recomend The Lord of the rings too. Good night:-) Wolf Since there was no mention what kind of perl books (beginner, etc.): I'd add: Object Oriented Perl by Damian Conway, I've also been wanting to check out Learning Perl Objects, References, Modules by Randall Schwartz. Advanced Perl Programming by Sriram Srinivasan (getting slightly out of date; seems I heard of updated edition coming ???). Effective Perl Programming by Joseph Hall is not bad. Writing Perl Modules for CPAN by Sam Tregar is pretty good if your going to write modules for CPAN. Extending Embedding Perl by Tim Jenness Simon Cozens is good if your going to get into Perl/XS. You'll definately want the Perl Cookbook mentioned above. It's the Perl equivelant of the Effective C++ books. 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 Harvey Kelly mailto:[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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: (U) What are the best Perl books out there ... More than 1 is fin e ... list as many as you like
Hi all, learning about basics like scalar variables and arrays etc. first is a little daunting. With the Bioinfo. book I was writing programs (well, If u are a novice to programming, well it might be a bit difficult initially - i agree. doing the exercises) straight away. Kinda like when I learnt French (pretentious? Moi?), I was speaking phrases and communicating before worrying about grammer - the grammer comes naturally the more you get into the language. well i 'd like to say that learning natural language (write/speak) is different from learning a programming language. in a natural language u get to the tune of the accent also along with grammar where as here it doesnt have any. well, we cant say i speak in Perl language ;-P. i have also noticed people who only start with those 'Perl for Bioinfo' books get stuck when they need to do something beyond what is taught in the book.coz learning a language at the first place increases the scope of applicativity which u might miss otherwise. i have learnt Perl language first then applying it for bioinfo. But I take your point and some people (most?) would find your suggestion helpful. well its up to u/them :-) Its just a suggestion. Harvey regards, KM Hi all, sorry i think its the otherway around. first one should know the technical basics of Perl language then dive into books like 'Beginning Perl for Bioinformatics'. As far as i have seen people who have learnt Perl language initially and then read books like those fared far better than people who took those books without knowing what Perl language is. regards, KM --- On Fri, Feb 06, 2004 at 12:08:21PM -, Harvey Kelly wrote: Hello, If you've no experience whatsoever, then Beginning Perl for Bioinformatics is very helpful - then move on to Learning Perl I guess. It assumes no prior knowledge, and although its focus is on Biology, it's all just data isn't it? Cheers, Harvey --- On 2/4/2004 10:17 PM, wolf blaum wrote: Hi, I like: Learning Perl by Randal Schwartz Tom Phoenix as a good introduction with tons of further references Programing Perl by Larry Wall, Tom Christiansen and Jon Orwant as the ultimate refernce and pillow Mastering Perl/Tk by Steve Lidie and Nancy Walsh for times when I dont have access to this mailing list and zentaras hints The Perl Cookbook by Tom Christiansen and Nathan Torkington for when I was to lasy to think for myself (or wanted to get depressed by how much better one could solve the problem Ive been working on in hunderts of lines) And even though I never read it in the linear way: Mastering regular expressions by Jeffrey Friedl Not to forget: perldoc perltoc or www.perldoc.com and The Hitchhickers Guide to the Galaxy and Last Chance to see by Douglas Adams. I guess others would recomend The Lord of the rings too. Good night:-) Wolf Since there was no mention what kind of perl books (beginner, etc.): I'd add: Object Oriented Perl by Damian Conway, I've also been wanting to check out Learning Perl Objects, References, Modules by Randall Schwartz. Advanced Perl Programming by Sriram Srinivasan (getting slightly out of date; seems I heard of updated edition coming ???). Effective Perl Programming by Joseph Hall is not bad. Writing Perl Modules for CPAN by Sam Tregar is pretty good if your going to write modules for CPAN. Extending Embedding Perl by Tim Jenness Simon Cozens is good if your going to get into Perl/XS. You'll definately want the Perl Cookbook mentioned above. It's the Perl equivelant of the Effective C++ books. 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 Harvey Kelly mailto:[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 Harvey Kelly mailto:[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: Search Replace in multiple files
[EMAIL PROTECTED] wrote: Hi, I have to search and replace 'foo' to 'bar' in all the files in a directory(has subdirectories). The files are about 40k in size. What is the most efficient way to implement this inside a perl program ? There are about 30 files to be processed. I went through perldoc perlrun and saw the code. I don't know if this is the most efficient way, but it works: #!/usr/bin/perl -w use strict; use File::Find; find \process, $ARGV[0]; sub process { $filename = $File::Find::name; open IN, $filename or die Couldn't open $filename for reading: $!; $^I = ; while (IN) { s/foo/bar/g; } close IN; print Updated file $filename\n; } - Jan -- If all else fails read the instructions. - Donald Knuth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: my in the perl syntax
Harshal borade wrote: Well I am very new to Perl. I have read Oreily's Camel book, but haven't found any thing about my that is used in any of the code. e.g my $var What is my supposed to be over here? I am new as well and by lurking in the groups I can tell you with great certainty to use perldoc. It is wonderful. In your case you would type the following: perldoc -f my perldoc -f my my EXPR my TYPE EXPR my EXPR : ATTRS my TYPE EXPR : ATTRS A my declares the listed variables to be local (lexically) to the enclosing block, file, or eval. If more than one value is listed, the list must be placed in parentheses. The exact semantics and interface of TYPE and ATTRS are still evolving. TYPE is currently bound to the use of fields pragma, and attributes are handled using the attributes pragma, or starting from Perl 5.8.0 also via the Attribute::Handlers module. See Private Variables via my() in perlsub for details, and fields, attributes, and Attribute::Handlers. HTH Robert -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: (U) What are the best Perl books out there ... More than 1 is fin e ... list as many as you like
Hello all, Yeah that does make sense, but my experience (and I'm only speaking for myself here) is that learning about basics like scalar variables and arrays etc. first is a little daunting. With the Bioinfo. book I was writing programs (well, doing the exercises) straight away. Kinda like when I learnt French (pretentious? Moi?), I was speaking phrases and communicating before worrying about grammer - the grammer comes naturally the more you get into the language. But I take your point and some people (most?) would find your suggestion helpful. Harvey --- Hi all, sorry i think its the otherway around. first one should know the technical basics of Perl language then dive into books like 'Beginning Perl for Bioinformatics'. As far as i have seen people who have learnt Perl language initially and then read books like those fared far better than people who took those books without knowing what Perl language is. regards, KM --- On Fri, Feb 06, 2004 at 12:08:21PM -, Harvey Kelly wrote: Hello, If you've no experience whatsoever, then Beginning Perl for Bioinformatics is very helpful - then move on to Learning Perl I guess. It assumes no prior knowledge, and although its focus is on Biology, it's all just data isn't it? Cheers, Harvey --- On 2/4/2004 10:17 PM, wolf blaum wrote: Hi, I like: Learning Perl by Randal Schwartz Tom Phoenix as a good introduction with tons of further references Programing Perl by Larry Wall, Tom Christiansen and Jon Orwant as the ultimate refernce and pillow Mastering Perl/Tk by Steve Lidie and Nancy Walsh for times when I dont have access to this mailing list and zentaras hints The Perl Cookbook by Tom Christiansen and Nathan Torkington for when I was to lasy to think for myself (or wanted to get depressed by how much better one could solve the problem Ive been working on in hunderts of lines) And even though I never read it in the linear way: Mastering regular expressions by Jeffrey Friedl Not to forget: perldoc perltoc or www.perldoc.com and The Hitchhickers Guide to the Galaxy and Last Chance to see by Douglas Adams. I guess others would recomend The Lord of the rings too. Good night:-) Wolf Since there was no mention what kind of perl books (beginner, etc.): I'd add: Object Oriented Perl by Damian Conway, I've also been wanting to check out Learning Perl Objects, References, Modules by Randall Schwartz. Advanced Perl Programming by Sriram Srinivasan (getting slightly out of date; seems I heard of updated edition coming ???). Effective Perl Programming by Joseph Hall is not bad. Writing Perl Modules for CPAN by Sam Tregar is pretty good if your going to write modules for CPAN. Extending Embedding Perl by Tim Jenness Simon Cozens is good if your going to get into Perl/XS. You'll definately want the Perl Cookbook mentioned above. It's the Perl equivelant of the Effective C++ books. 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 Harvey Kelly mailto:[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 Harvey Kelly mailto:[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: Search Replace in multiple files
Please disregard my post, I mixed up the magic and the less magic FILEHANDLE. -- These are my principles and if you don't like them... well, I have others. - Groucho Marx -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Search Replace in multiple files
Chetak Sasalu wrote: I have to search and replace 'foo' to 'bar' in all the files in a directory(has subdirectories). The files are about 40k in size. On the command line I would do it as, find ./mydir/ -type f -print | xargs perl -pi -e 's/foo/bar/' No backup of the original files required.I am brave. What is the most efficient way to implement this inside a perl program ? There are about 30 files to be processed. I went through perldoc perlrun and saw the code. use strict; use warnings; local @ARGV = grep -f, ./mydir/*; $^I = ''; while () { s/foo/bar/g; print; } Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Search Replace in multiple files
On 02/06/04 07:45, [EMAIL PROTECTED] wrote: PS: I see this term 'foo' 'bar' in many programming books, what is the etymology of this? It is derived from a technical acronym FUBAR - [EMAIL PROTECTED] Up Beyond All Repair (or Recognition). 'foo', 'bar' is just a play on the original acronym - A joke forever obsorbed into common usage. 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: my in the perl syntax
From: Robert [EMAIL PROTECTED] Subject: Re: my in the perl syntax Date: Fri, 06 Feb 2004 07:57:39 -0500 Hi the best to understand is like in the next code snippet: sub SubA { my $var1 ; } In this function the var $var will be local and so can not be accessed from outside. (Or if you have a global variable $var, it's actual value will be totally different.) Gurus will explain better.. Harshal borade wrote: Well I am very new to Perl. I have read Oreily's Camel book, but haven't found any thing about my that is used in any of the code. e.g my $var What is my supposed to be over here? I am new as well and by lurking in the groups I can tell you with great certainty to use perldoc. It is wonderful. In your case you would type the following: perldoc -f my perldoc -f my my EXPR my TYPE EXPR my EXPR : ATTRS my TYPE EXPR : ATTRS A my declares the listed variables to be local (lexically) to the enclosing block, file, or eval. If more than one value is listed, the list must be placed in parentheses. The exact semantics and interface of TYPE and ATTRS are still evolving. TYPE is currently bound to the use of fields pragma, and attributes are handled using the attributes pragma, or starting from Perl 5.8.0 also via the Attribute::Handlers module. See Private Variables via my() in perlsub for details, and fields, attributes, and Attribute::Handlers. HTH Robert -- 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: my in the perl syntax
Well I am very new to Perl. I have read Oreily's Camel book, but haven't found any thing about my that is used in any of the code. e.g my $var What is my supposed to be over here? Since the Camel is a reference more than a tutorial and because it is already a pretty thick tome many of the examples in it will not include 'my' as that is really a best practice not an absolute necessity to demonstrating code in a reference setting, so to make example code shorter and easier to understand. Having said that, it *is* a best practice and you *should* be doing, use strict; use warnings; In all of your code, which will necessitate the use of 'my' very often. http://perl.plover.com/FAQs/Namespaces.html Is an excellent article on scoping in Perl, and should clear things up with regards to 'my' come back if you have further questions, 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: Search Replace in multiple files
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: : : I went through perldoc perlrun and saw the code. : : I thought it as a criminal waste of time to try and : modify that code for my purpose, when I can ask you : folks :-) Perhaps I am misunderstanding you, but that sounds to me like you would rather get us to do your work for free instead of you acquiring the mental tools to do it yourself. In the long run, that doesn't really help you, does it? Many of us are here to *help* you get past the problems you are having with your code. We are not here as a code writing resource. Again, perhaps I am misreading your message. If so, my apologies. If not, try to find answers on your own first. Look at the documentation that comes with perl. Search the internet with Google. We help a lot of folks here, but we assume you have at least tried to solve things yourself. Take a look at the archives. Many of us that help very rarely ask questions here. I, for one, have learned how to answer most of my questions through research and by wasting my time and *not* asking here first. I'll bet a lot of programmers more experienced then me do the same. : PS: I see this term 'foo' 'bar' in many programming : books, what is the etymology of this? RFC 3092 - Etymology of Foo: http://www.faqs.org/rfcs/rfc3092.html BTW, this was the first link returned by Google. You could have at least tried to find it on your own. http://www.google.com/search?q=foo+etymology 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
RE: Search Replace in multiple files
Wouldn't it be better to not waste your time with this kind of response??? Ned Cunningham POS Systems Development Monro Muffler Brake 200 Holleder Parkway Rochester, NY 14615 (585) 647-6400 ext. 310 [EMAIL PROTECTED] -Original Message- From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] Sent: Friday, February 06, 2004 9:54 AM To: [EMAIL PROTECTED] Subject:RE: Search Replace in multiple files [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: : : I went through perldoc perlrun and saw the code. : : I thought it as a criminal waste of time to try and : modify that code for my purpose, when I can ask you : folks :-) Perhaps I am misunderstanding you, but that sounds to me like you would rather get us to do your work for free instead of you acquiring the mental tools to do it yourself. In the long run, that doesn't really help you, does it? Many of us are here to *help* you get past the problems you are having with your code. We are not here as a code writing resource. Again, perhaps I am misreading your message. If so, my apologies. If not, try to find answers on your own first. Look at the documentation that comes with perl. Search the internet with Google. We help a lot of folks here, but we assume you have at least tried to solve things yourself. Take a look at the archives. Many of us that help very rarely ask questions here. I, for one, have learned how to answer most of my questions through research and by wasting my time and *not* asking here first. I'll bet a lot of programmers more experienced then me do the same. : PS: I see this term 'foo' 'bar' in many programming : books, what is the etymology of this? RFC 3092 - Etymology of Foo: http://www.faqs.org/rfcs/rfc3092.html BTW, this was the first link returned by Google. You could have at least tried to find it on your own. http://www.google.com/search?q=foo+etymology 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Script Kiddie issues
Frankly I use the apache filter to check for people looking for cmd.exe or root.exe or any one of a dozen files, and instead of my log files filling with their looks they are sent an iframe html page with a virus built in that formats their windows system. If they aren't running windows then it it still an annoyance because they get nowhere, but if it is windows, then I get to have some fun with them. Just my $.02. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Net::SMTP Problem - Bad Protocol
I have a problem with Net::SMTP running a Win32 server (groan). It works fine from the command line but when I try it through cgi I get: Net::SMTP: Bad protocol 'tcp' at... All help greatly appreciated :) Cheers, Nigel Managing Director MIS Web Design http://www.miswebdesign.com/ Administrator AccessifyForum.com http://www.accessifyforum.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Script to parse files
I've been working with this since wolf and jeff and john sent me some stuff, I think I actually based everything on wolf's code excerpts. I'm sure my final code is going to not be perfect, but at least I have the piece of mind of knowing that I can get this thing some better then it was. I'm still not sure on making it a sub that I can use on anything, but I'll deal with that issue another day. Robert -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: * CSV to HTML * please send cgi-beginner listserv address
Thanks to all who helped - please give me the beginners cgi listserv email Thanks, Gregg - Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online
Re: Sending mails
I'm still learning myself and haven't tried sending email's from perl scripts (yet). I did however notice one typo which might help you grab more info on what's going on. Check the below in your code. Change 'use warnigs' to 'use warnings' Hopefully it will help give you a bit more to go on. #!/usr/bin/perl use warnigs; use strict; use MIME::Lite; use CGI 'param'; I tried using this code but it's giving error. Can you explain in details pls as this is my first perl script don't know much of programming. Thanks Nilanjana --- On Wed, 4 Feb 2004 14:07:43 +0530, [EMAIL PROTECTED] (Nilanjana Bhattacharya) wrote: Hello everybody, I have two radio buttons in a form. I want - When any one clicks on button A a mail will be sent to A when any one clicks on button B mail will be sent to button B. In both the cases whether someone clicks on A or B I will receive a mail. Can anyone help me with the coding pls? Well here is some untested code which will give you a start. #!/usr/bin/perl use warnigs; use strict; use MIME::Lite; use CGI 'param'; # Assign variables to arguments # you need your html form to send these my $a = param{'button_a_address'} || undef; my $b = param{'button_b_address'} || undef; my $me = '[EMAIL PROTECTED]'; my $addr; if(defined $a){$addr = $a}else{$addr = $b} my $msg = MIME::Lite-new( From ='[EMAIL PROTECTED]', To =$addr, Bcc =$me, Subject ='test message', Type ='TEXT', Data ='This is a test', ); $msg-attach(Type ='application/octet-stream', Encoding ='base64', Path ='test.zip', ); $msg-send; # Print HTML Out print Content-type: text/html\n\n; print END; html head titleMail Sent!!/title /head br center brbrThe file has been successfully sent to print $addr; /center /body /html **END** __END__ -- 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 Implement a BNF syntax in perl?
Hi, I have a long BNF (Backus-naur form) for parsing a protocol message. Suppose I want to implement a BNF like this Response = Status-line *(message-header) CRLF [Message-body] status-Line = SIP-Version SP Status-Code SP Reason-Phrase CRLF SP = space character .. . Like this I have a very long BNF. How can I implement this BNF and parse a message that satisfies this BNF in perl ? Any suggestions would be of great help to me. Thanks, Balaji Yahoo! India Mobile: Ringtones, Wallpapers, Picture Messages and more.Download now.
skipping lines of input from another program...
the following is my script that i am working on- it fails to do quite the right thing.. qouting from one of the comments below:: #skip_lines() is supposed to skip some lines of output. #The problem is, that it DOESN'T even though the debug print statement # print trash is $trash \n; #debug shows that it works- #after leaving the for loop, it seems that CMD re-winds itself... # i am flummuxed!! #!/usr/bin/perl # # # Screen parser for Service Information System utilities # on RAXP # History:: # 5 feb 2004 skeleton and parse routines built (w/ test values.) wmw #- use strict; use diagnostics; #-- my $command = /home/willy/Documents/conditional.testbed.exp; my $pattern = inittab; my $skip; $skip-[0] = 2; $skip-[1] = 2; my $table; $table-{PART} = INVENTORY; #-- # $pattern is only a string right now because i am assuming # that the screens will be consistant with each call. $skip should produce # enough flexibility for reuse. open (CMD , $command|) or die Could not execute $command : $!; parse_and_extract($pattern,$skip,$table); close CMD; #the following routine takes each line of the input (from a different #program). When the pattern is matched, it calls get_inventory(). sub parse_and_extract { my $pattern = shift; #what we look for. my $skips = shift; #array ref. each value is # of lines to skip # over. my $table = shift; #values are stored here. (hash reference) while (CMD) { get_inventory ($table,$skips) if ($_=~m/$pattern/); print parse_and_extract\n\r; #debug print $_\n\r; #debug } } #the following routine assigns a key/value pair to a hash reference ($table) #skip_lines() is supposed to skip some lines of output. #The problem is, that it DOESN'T even though the debug print statement # print trash is $trash \n; #debug shows that it works- #after leaving the for loop, it seems that CMD re-winds itself... # i am flummuxed!! sub get_inventory { my $table = shift; my $skip = shift; #$skip is an array reference for the case that several #different screens will have to be parsed in the future- #in which case, a flag will have to be added to determine #which value in the array reference will be used. # (perhaps $skip should be a hash of arrays?) #first we skip the lines from the pattern match up to #the line with the value we want. skip_lines ($skip-[0]); my $partnumber = $_;#check syntax- is $_ instead? #skip lines to the next value... skip_lines ($skip-[1]); my $inventory = $_;#check syntax- is $_ instead? $table-{$partnumber}=$inventory; #print keys:: ; #debug #print keys(%$table); print keys to the table\n; #debug #print get_inventory() $_\n; #debug } sub skip_lines { my $lines = shift; #number of lines in file to skip over print in skip_lines() $_ before skip\n; #debug #CMD for 1..$lines; #not functioning... for (0..$lines){ my $trash = CMD; print trash is $trash \n; #debug } print in skip_lines() $_ after skip\n; #debug } #--- the following is the test expect script that i am using- as far as i can tell, it's working fine :/ (there's extra stuff in there since i was trying to learn how to use if statements earlier...) #!/usr/bin/expect -f #set ps $argv 0 set ps password spawn telnet localhost expect ogin: send willy\n expect word: send $ps\n expect terminal:* send ls\n #-- set file Desktop.ini set counter 1 while {$counter 5} { send echo $counter \n ls $file\n expect No such file {set counter [expr $counter + 1]} expect $file {set counter 200} sleep 2 } send ls\n\n sleep 2; expect terminal { if {$counter 200} { global subject set subject failed to produce report #expect terminal:* send w\n } if {$counter 100} { #expect terminal:* send date\n } } expect terminal send cd /etc\n expect terminal send ls\n #-- interact thanks, willy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Script to parse files
For Quality purpouses, LoneWolf 's mail on Friday 06 February 2004 16:57 may have been monitored or recorded as: I've been working with this since wolf and jeff and john sent me some stuff, I think I actually based everything on wolf's code excerpts. I'm sure my final code is going to not be perfect, but at least I have the piece of mind of knowing that I can get this thing some better then it was. I'm still not sure on making it a sub that I can use on anything, but I'll deal with that issue another day. easy: (notice: thats the same script as priviously but has the parse in a sub:) ---snip--- #!/usr/bin/perl use strict; use warnings; my (@fields, $lng); sub whatever { if (@_) { foreach my $infile (@_) { my ($i,$rec); open INFILE, $infile or die Can't open $infile: $!; open OUTFILE, ${infile}.out or die Can't open ${infile}.out at home: $!; while (INFILE) { $rec++; chomp; [EMAIL PROTECTED] = split /\s*\|\s*/, $_; $fields[0] =~ s/^\s+//; #there is probably a way to get rid of the trailing spaces in the first entry using split,I just couldnt think of any. $lng = @fields unless $lng; #set $lng for first record print The following record: $i has , scalar @fields, fields as compared to $lng fields in the first record! Skip. : $_\n and next unless $lng == @fields; #poor quality control of your input data: check if all reords have the same number of fields or skip and print record otherwise. $i++; print OUTFILE $i; print OUTFILE |$_ foreach (@fields); print OUTFILE |$fields[0]\n; #your trailing ID } close INFILE; close OUTFILE; print Read $rec records from ./sql/$infile and printed $i into ./ ${infile}.out\n; } #end foreach return 1; } else {return undef;} } #end sub whatever ---snap--- call it with whatever('path/to/firstfile', 'path/to/secondfile',...) Enjoy, Wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Reg. string matching using reg-exp
Hi, I am a novice to perl programming. When I execute the following code, I get always No Match. I guess my reg-exp is correct. I also tried changing $line= INVITE sip:[EMAIL PROTECTED] SIP/2.0; to have double quotes and a backslash char before @ symbol. Even then it gives me No Match. I appreciate your help. #!/usr/bin/perl -w my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0'; if($line =~ /^\s*(\w+)\s*(.*)\s+(sip\/\d+\.\d+)\s*\r\n/i) { print \nSIP Method: ,$1; print \nRequest URI: ,$2; print \nSIP Version: ,$3; } else { print No Match; } Thanks, Balaji Yahoo! India Mobile: Ringtones, Wallpapers, Picture Messages and more.Download now.
RE: Reg. string matching using reg-exp
It looks like there is no '\r\n' at the end of $line. -Original Message- From: Balaji Thoguluva [mailto:[EMAIL PROTECTED] Sent: Friday, February 06, 2004 11:45 AM To: [EMAIL PROTECTED] Subject: Reg. string matching using reg-exp #!/usr/bin/perl -w my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0'; if($line =~ /^\s*(\w+)\s*(.*)\s+(sip\/\d+\.\d+)\s*\r\n/i) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reg. string matching using reg-exp
For Quality purpouses, Balaji Thoguluva 's mail on Friday 06 February 2004 20:44 may have been monitored or recorded as: Hi, I am a novice to perl programming. When I execute the following code, I get always No Match. I guess my reg-exp is correct. I also tried changing $line= INVITE sip:[EMAIL PROTECTED] SIP/2.0; to have double quotes and a backslash char before @ symbol. Even then it gives me No Match. I appreciate your help. #!/usr/bin/perl -w my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0'; if($line =~ /^\s*(\w+)\s*(.*)\s+(sip\/\d+\.\d+)\s*\r\n/i) Do you have the \r\n at the end of $line? Wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Reg. string matching using reg-exp
Use the 's' option at the end of your regex after the closing '/'. $var =~ /match\nsomething\nelse/s; read 'perldoc perlre' for more about regexes. Also, please reply to the list next time, because I might not be at my desk or able to reply, and someone else probably will. _ From: Balaji Thoguluva [mailto:[EMAIL PROTECTED] Sent: Friday, February 06, 2004 12:07 PM To: Tim Johnson Subject: RE: Reg. string matching using reg-exp Thanks Tim Johnson. I removed the /r/n from the reg-ex and it works. I have another question. How to assign a multiline string or string having many lines(strings having \n) to a $string-variable?. In C, there is a \ operator. Thanks for your help, Balaji
Re: Script to parse files
For Quality purpouses, wolf blaum 's mail on Friday 06 February 2004 20:15 may have been monitored or recorded as: easy: (notice: thats the same script as priviously but has the parse in a sub:) ---snip--- #!/usr/bin/perl use strict; use warnings; my (@fields, $lng); ... and that my (@fields, $lng); belings in the sub wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Reg. string matching using reg-exp
On Feb 6, Balaji Thoguluva said: Thanks Tim Johnson. I removed the /r/n from the reg-ex and it works. I have another question. How to assign a multiline string or string having many lines(strings having \n) to a $string-variable?. In C, there is a \ operator. You don't need to do anything special in Perl. $string = This is a very long string that spans many lines; Or you can use a 'here-doc'. $string = END OF STRING; this is a very long string that spans many lines END OF STRING -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reg. string matching using reg-exp
Balaji thoguluva wrote: I am a novice to perl programming. When I execute the following code, I get always No Match. I guess my reg-exp is correct. I also tried changing $line= INVITE sip:[EMAIL PROTECTED] SIP/2.0; to have double quotes and a backslash char before @ symbol. Even then it gives me No Match. I appreciate your help. #!/usr/bin/perl -w my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0'; if($line =~ /^\s*(\w+)\s*(.*)\s+(sip\/\d+\.\d+)\s*\r\n/i) { print \nSIP Method: ,$1; print \nRequest URI: ,$2; print \nSIP Version: ,$3; } else { print No Match; } The string you show, as others have pointed out, has no \r\n terminator. Even if you're pulling your record from a text file, Perl will try hard to change all platforms' line terminators to a simple \n in the record you actually read. And even having said that, there's no reason to match /all/ of the string if you're just extracting sub-fields: it's unlikely to help to be told that your record doesn't actually end in /\s*\r\n/. I think your regex should look like this: my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0'; $line =~ /^\s*(\w+)\s+(.*)\s+(sip\/\d+\.\d+)/i; print map $_\n, $1, $2, $3; **OUTPUT INVITE sip:[EMAIL PROTECTED] SIP/2.0 HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reg. string matching using reg-exp
Jeff 'Japhy' Pinyan wrote: On Feb 6, Balaji Thoguluva said: Thanks Tim Johnson. I removed the /r/n from the reg-ex and it works. I have another question. How to assign a multiline string or string having many lines(strings having \n) to a $string-variable?. In C, there is a \ operator. You don't need to do anything special in Perl. $string = This is a very long string that spans many lines; Or you can use a 'here-doc'. $string = END OF STRING; this is a very long string that spans many lines END OF STRING In C, newlines have to be introduced explicitly as \n. A literal newline character (the end of a source record) has to be escaped to make it 'vanish', otherwise it should throw a compilation error. In Perl: my $string = One Two Three ; In C: char *string = One\n\ Two\n\ Three\n\ ; or, because consecutive C string constants are implicitly concatenated: char *string = One\n Two\n Three\n ; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: skipping lines of input from another program...
in the post that i am now replying to, i said that i couldn't get the program to skip lines as it parsed through the output of another program. i have solved the problem- but i do not know WHY this works the way it does. SNIP this worked great :) (thanks to drieux) - in fact, it would let me have several programs input to this one at once :) (if i'm not mistaken) open (CMD , $command|) or die Could not execute $command : $!; parse_and_extract($pattern,$skip,$table); close CMD; SNIPPED for brevety sub skip_lines { my $lines = shift; #number of lines in file to skip over print in skip_lines() $_ before skip\n; #debug #CMD for 1..$lines; #not functioning... for (0..$lines){ my $trash = CMD; print trash is $trash \n; #debug } the fix was to replace the above for loop with the following:: for my $trash (0..$lines) { $_ = CMD; print the line skipped is $_\n; #debug } print in skip_lines() $_ after skip\n; #debug } well- i don't understand it. WHY does this work? if someone could clarify the mechanics behind this behaviour, i would be very grateful! thank you much, willy -- 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 rearrange columns
At 03:31 PM 2/5/2004 -0800, david wrote: Shiping Wang wrote: Hi David, thanks for your response. My concern is that if the data has hundreds columns (which the order information I can get from another array or file) need to be rearranged, how can I do it. Here is my test program, it seems working. Any suggestion or concern??? Shiping ___ #!/usr/bin/perl # sortColumns.pl use warnings; use strict; use Math::Matrix; [snip] i have never used Math::Matrix so i am not sure how it behave or works but your code seems overly complicated for such a simple problem. even there are unknown number of columns, as long as the first line (header) is there to suggest the right order, you don't need to sort anything or do matrix operation. for example, the following sorts the file and it doesn't need to know how many columns to sort. you can have hundreds or thousands of columns: #!/usr/bin/perl -w use strict; my $j = 0; my %i = map{$_ = $j++} grep $_, split(/\D+/,my $line = DATA); my @c = sort {$a = $b} keys %i; #-- #-- header #-- print join(\t,(split /\s+/,$line)[EMAIL PROTECTED]@c}]),\n; # Although I can guess this piece of code do the sorting then print out, but don't quite understand how it works, especially [EMAIL PROTECTED]@c}]. @c = (1 2 3 4 5 6) and @[EMAIL PROTECTED] = ( 0 3 5 1 2 4) get all the values of %i ? Something like ($i{1} $i{2} ${6}) then it likes print join(\t, @[EMAIL PROTECTED]@c}]),\n; which become to: print join(\t, @_[ 0, 3, 5, 1, 2, 4]),\n; perl automatically sort array before printing? Did I understand this right? Thank you very much, Shiping #-- #-- the rest #-- while(DATA){ print join(\t,(split)[EMAIL PROTECTED]@c}]),\n; } __DATA__ col1col4col5col2col6col3 Abc 12.88 left1 15.7 Def 13.89 top 0 19.7 gef 14.89 left0 19.7 Dgf 12.39 right 4 99.6 cef 16.84 right 0 89.7 baf 32.87 bottom 5 79.8 efg 16.85 right 0 56.7 etg 12.82 left7 34.7 __END__ prints: col1col2col3col4col5col6 Abc left15.712.88 1 Def top 19.713.89 0 gef left19.714.89 0 Dgf right 99.612.39 4 cef right 89.716.84 0 baf bottom 79.832.87 5 efg right 56.716.85 0 etg left34.712.82 7 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: skipping lines of input from another program...
William M West wrote: in the post that i am now replying to, i said that i couldn't get the program to skip lines as it parsed through the output of another program. i have solved the problem- but i do not know WHY this works the way it does. SNIP this worked great :) (thanks to drieux) - in fact, it would let me have several programs input to this one at once :) (if i'm not mistaken) Get just one working, for now :) [snip] sub skip_lines { my $lines = shift; #number of lines in file to skip over print in skip_lines() $_ before skip\n; #debug #CMD for 1..$lines; #not functioning... for (0..$lines){ my $trash = CMD; print trash is $trash \n; #debug } the fix was to replace the above for loop with the following:: for my $trash (0..$lines) { $_ = CMD; print the line skipped is $_\n; #debug } print in skip_lines() $_ after skip\n; #debug } well- i don't understand it. WHY does this work? if someone could clarify the mechanics behind this behaviour, i would be very grateful! Hi Willy. It's because $_ wasn't being assigned. Your original calls to skip_lines read like this: skip_lines ($skip-[0]); my $partnumber = $_; skip_lines ($skip-[1]); my $inventory = $_; but you were reading your record into $trash instead. It's a bad idea to use $_ as a global variable. It's meant to be used invisibly and in very close scope in things like: while () { s/this/that/g; print; } and not for passing stuff out of subroutine calls. If you're not sure then just don't explicitly mention '$_' at all and you should be safe. I think you have an over-elaborate design for this anyway. I think it's likely that your data can be processed better than just by skipping 'n' lines between useful records. And even if this is the way you want to go there's nothing wrong with CMD for 1 .. $skip-[0] my $partnumber = CMD; CMD for 1 .. $skip-[1] my $inventory = CMD; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Shortcuts and ability to force to server
My Sys Admin have shortcuts ( 16 bit ) which they have set their target or cmd pointing to a server location. Is there anyway via Perl or ??? to force the processing to be done on the server verses workstation which invoked the shortcut? Make any sense? Any questions and/or problems, please let me know. Thanks. Wags ;) Int: 9-8-002-2224 Ext: 408-323-4225x2224 ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: How to rearrange columns
Shiping Wang wrote: [snip] #-- #-- header #-- print join(\t,(split /\s+/,$line)[EMAIL PROTECTED]@c}]),\n; # Although I can guess this piece of code do the sorting then print out, but don't quite understand how it works, especially [EMAIL PROTECTED]@c}]. no sorting is happening in this line, the sorting is done above it and only once. here is the originally code and explanation: my $j = 0; #-- #-- here we are building a hash %i that look like: #-- #-- $i{1} = 0; #-- column 1 should become column 1 #-- $i{4} = 1; #-- column 2 should become column 4 #-- $i{5} = 2; #-- column 3 should become column 5 #-- $i{2} = 3; #-- column 4 should become column 2 #-- $i{6} = 4; #-- column 5 should become column 6 #-- $i{3} = 5; #-- column 6 should become column 3 #-- my %i = map{$_ = $j++} grep $_, split(/\D+/,my $line = DATA); #-- #-- here we are building an array @c that look like: #-- #-- $c[0] = 1; #-- $c[1] = 2; #-- $c[2] = 3; #-- $c[3] = 4; #-- $c[4] = 5; #-- $c[5] = 6; #-- #-- you don't really need this @c array #-- my @c = sort {$a = $b} keys %i; #-- #-- header #-- print join(\t,(split /\s+/,$line)[EMAIL PROTECTED]@c}]),\n; #-- #-- @i{...} is called a hash slice in Perl. @c expands to: #-- #-- (1,2,3,4,5,6); #-- #-- @[EMAIL PROTECTED] then become: #-- #-- @i{1,2,3,4,5,6} #-- #-- which is translated into: #-- #-- ($i{1},$i{2},$i{3},$i{4},$i{5},$i{6}); #-- #-- which is then translated into: #-- #-- (0,3,5,1,2,4); #-- #-- finally: #-- #-- (split /\s+/,$line)[0,3,5,1,2,4] #-- #-- created an annoy. list which we then immediately #-- extract in this order. this is the right order #-- for your data file. #-- #-- #-- the rest #-- while(DATA){ #-- #-- same thing as above #-- print join(\t,(split)[EMAIL PROTECTED]@c}]),\n; } __END__ perl automatically sort array before printing? no. if you need to sort it, you need to sort it manually. Perl does not sort the array for you before printing. 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: Reg. string matching using reg-exp
Rob Dixon wrote: In C, newlines have to be introduced explicitly as \n. A literal newline character (the end of a source record) has to be escaped to make it 'vanish', otherwise it should throw a compilation error. In Perl: my $string = One Two Three ; In C: char *string = One\n\ Two\n\ Three\n\ ; or, because consecutive C string constants are implicitly concatenated: char *string = One\n Two\n Three\n ; or don't quote them is you have an ANSI C compiler: #define TEST(s) printf(%s\n,#s) int main(int argc,char* argv[]){ TEST(\n \n \n see you!); } prints: see you! 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: my in the perl syntax
Harshal borade wrote: Well I am very new to Perl. I have read Oreily's Camel book, but haven't found any thing about my that is used in any of the code. e.g my $var What is my supposed to be over here? Perhaps this article will help you understand: http://perl.plover.com/FAQs/Namespaces.html 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: Search Replace in multiple files
Chetak Sasalu wrote: Hi, Hello, I have to search and replace 'foo' to 'bar' in all the files in a directory(has subdirectories). The files are about 40k in size. On the command line I would do it as, find ./mydir/ -type f -print | xargs perl -pi -e 's/foo/bar/' No backup of the original files required.I am brave. What is the most efficient way to implement this inside a perl program ? There are about 30 files to be processed. I went through perldoc perlrun and saw the code. I thought it as a criminal waste of time to try and modify that code for my purpose, when I can ask you folks :-) use File::Find; local ( $^I, @ARGV ) = ''; find( { no_chdir = 1, wanted = sub { -f and push @ARGV, $_ } }, './mydir' ); s/foo/bar/g, print while ; 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: How to Implement a BNF syntax in perl?
On 02/06/04 12:49, Balaji Thoguluva wrote: Hi, I have a long BNF (Backus-naur form) for parsing a protocol message. Suppose I want to implement a BNF like this Response = Status-line *(message-header) CRLF [Message-body] status-Line = SIP-Version SP Status-Code SP Reason-Phrase CRLF SP = space character .. . Like this I have a very long BNF. How can I implement this BNF and parse a message that satisfies this BNF in perl ? Any suggestions would be of great help to me. Have you looked at Parse::RecDescent: http://search.cpan.org/dist/Parse-RecDescent/ 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: Search Replace in multiple files
Ned Cunningham wrote: Wouldn't it be better to not waste your time with this kind of response??? Ned Cunningham POS Systems Development Hi Ned, I'd say that it depends on whether you see the OP as a potential programmer. If so, then no, it would not be better. If the OP takes a hint and takes another look at his approach to learning, then this is time well spent. If not, the yes, this would certainly be a gratuitous post. OTOH, it might still help the OP clarify his purpose and direction. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Module for Country/Country Codes Lists
On Wed, 4 Feb 2004, Randy W. Sims wrote: On 2/4/2004 11:36 AM, Shlomi Fish wrote: Hi! My name is Shlomi Fish and I am a co-developer of the WWW::Form module: http://search.cpan.org/~bschmau/WWW-Form-1.13/ Benjamin Schmaus (WWW::Form's main developer) and I decided it would be a good idea for the module or an extension of it to provide common form controls like a country list or a U.S. states list. To do so we need a module that returns a country list. Ideally what we would like is for it to return a refernece to a hash of country codes (US, IL, UK, RU, etc.) that each map to a contry name (United States, Israel, United Kingdom, Russia). Or alternatively, a similar interface with similar capabilites. We enumberated our needs here: http://benschmaus.com/cgi-bin/twiki/view/Main/WwwFormCountryList So, is there a good module for doing that on CPAN that is also actively maintained and updated? You should be able to build on Locale::Country Locale::SubCountry. Thanks, we'll take a look. Regards, Shlomi Fish Regards, Randy. -- Shlomi Fish[EMAIL PROTECTED] Home Page: http://t2.technion.ac.il/~shlomif/ You are banished! You are banished! You are banished! Hey? I'm just kidding! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response