RE: computations with backreferences
: I know you can : basically stick any function in a regex but I don't : know how. Hence, the code below won't work: To evaluate the right side of a substitution as an expression (rather than a literal string), you stick an e after the last delimiter. : $_=~s/^[A-Z]\t(\d{1,2})\t.*\t(\d{2})\t.*/$1\t$2\t($1+$2)/2/; : : The forward slash that would terminate wrongly the : regex is actually a divide by. : What is the correct way to do it? You can use any delimiters you like in your substitution, either a single character like: s|foo|bar| or matched pairs like s{foo}{bar} --Art ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: Regular Expression, matching dates
: : I need a regular expression that will match dates in the : following format. : : January 01, 2001 : January 15, 2001 : February 01, 2001 : : so on. All dates are spelled out March, April, May... : if ($date_string =~ /(\w+)\s+(\d{1,2}),\s+(\d{4})/) { $month = $1; $day = $2; $year = $3; } You can make the regex as strict or as loose as you want. I've written it to allow any number of white-space characters between each piece of the date, but you may want to restrict it to only one space character. OTOH, mine is require exactly 1 or 2 digits in the day and 4 in the year, which you may want to adapt to suit your needs. --Art ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: grep
You can assemble the regular expression as a string and then use that. So if your users call the script like: foo.pl .c .cpp .h .rc you could do something like this: my $regex = join (|, @ARGV); # $regex is now '.c|.cpp|.h|.rc' $regex =~ s/\./\\./g; # escape the periods my @filtered = grep { /($regex)$/ } @unfiltered; --Art : -Original Message- : From: Tanya Graham [mailto:[EMAIL PROTECTED]] : Sent: Monday, June 04, 2001 2:16 PM : To: 'Troy Sniff'; [EMAIL PROTECTED] : Subject: RE: grep : : : ok, the grep works when i hardcode it. any ideas on how to take the : extensions from the command line? would the user have to type : it in the : correct format, i.e. (\.c|\.cpp|\.h|\.rc) : thanks : tanya : : -Original Message- : From: Troy Sniff [mailto:[EMAIL PROTECTED]] : Sent: Monday, June 04, 2001 11:19 AM : To: [EMAIL PROTECTED] : Subject: RE: grep : : : Why not put the . before the (). This way if the list of type of files : is long, you don't have to retype the \. every time. : : my @filtered = grep { /\.(html|asp)$/ } @unfiltered; : : Just a thought. : : Troy : : : : -Original Message- : From: [EMAIL PROTECTED] : [mailto:[EMAIL PROTECTED]] On Behalf Of : Arthur Cohen : Sent: Monday, June 04, 2001 11:47 AM : To: Tanya Graham; [EMAIL PROTECTED] : Subject: RE: grep : : : Grep is what you want, e.g. : : : : my @filtered = grep { /(\.html|\.asp)$/ } @unfiltered; : : : : --Art : : : : : -Original Message- : : : From: Tanya Graham [mailto:[EMAIL PROTECTED]] : : : Sent: Monday, June 04, 2001 1:38 PM : : : To: [EMAIL PROTECTED] : : : Subject: grep : : : : : : : : : Hi, : : : I need to be able to take my array of files @files, and : : : exclude files that : : : aren't of a certain extensions. more specifically, one of my : : : arguments on : : : the command line is a comma-separated list of file extensions : : : and i need to : : : alter only the files with those extensions...do i use grep : : : for this? is : : : there a better way? : : : thank you : : : tanya graham : : : : : : -Original Message- : : : From: Troy Sniff [mailto:[EMAIL PROTECTED]] : : : Sent: Monday, June 04, 2001 10:17 AM : : : To: [EMAIL PROTECTED] : : : Subject: Determining memory leak : : : : : : : : : I have a suspicion I have a memory leak in a script I am working on. : : : : : : How can I go about determining the amount of memory the : : : script is using? : : : : : : Is there a module that will report the amount of memory used while : : : executing parts of the script. Maybe reporting the amount : used as it : : : jumps throughout the script and subs? : : : : : : Troy : : : : : : ___ : : : Perl-Win32-Users mailing list : : : [EMAIL PROTECTED] : : : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : : : ___ : : : Perl-Win32-Users mailing list : : : [EMAIL PROTECTED] : : : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : : : : : ___ : Perl-Win32-Users mailing list : [EMAIL PROTECTED] : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : : : ___ : Perl-Win32-Users mailing list : [EMAIL PROTECTED] : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : ___ : Perl-Win32-Users mailing list : [EMAIL PROTECTED] : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: grep
: : : if i take the argument from a flag (so i won't be using : @ARGV, but opt_x) : would i still be able to use join? You can do what you want to do, but I'm not sure exactly what you're trying to do. How are you calling the program from the command line, and how are you pulling the command-line arguments into variables? If the file extentions are already in a single scalar variable (e.g. comma-separated or something) rather than an array like @ARGV, then you may need to do a split first, then a join, or you may just be able to separate your comma separator (or whatever) with a | character. --Art ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: grep
Should be =~ instead of = --Art : -Original Message- : From: Tanya Graham [mailto:[EMAIL PROTECTED]] : Sent: Monday, June 04, 2001 4:10 PM : To: Tanya Graham; [EMAIL PROTECTED] : Subject: RE: grep : : : $regex is right, until the second statement is executed. then : it disappears. : : my $regex = $opt_e; : : my $regex = s/\s*,\s*/|/g; : : any ideas why? : thanks : tanya : -Original Message- : From: Arthur Cohen [mailto:[EMAIL PROTECTED]] : Sent: Monday, June 04, 2001 12:02 PM : To: Tanya Graham; [EMAIL PROTECTED] : Subject: RE: grep : : : : : : : : this is how it is called: : : AddHeader.pl -f [directory name] -e [extension list] : : this tells the program to add a header to the files with extensions : : extension list in directory name. I would actually : : prefer to have them : : comma separated, so can you explain how to replace the commas : : with |? i : : know i've seen that function before, but i can't remember what it is : : called... : : Heh heh... it's called s... :) : : Assuming that your users might add some extra spaces around : the commas: : : $extensions = '.c, .cpp , .h'; # set up some test data : $extensions =~ s/\s*,\s*/|/g; : : # $extensions should now be '.c|.cpp|.h' ... you still need to escape : the periods : : If you want to find out what the regular expression in the : substitution : command is doing, see the perlre reference. : : --Art : ___ : Perl-Win32-Users mailing list : [EMAIL PROTECTED] : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: Version of Perl
Type perl -v from the command line. --Art : -Original Message- : From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] : Sent: Tuesday, May 22, 2001 4:23 PM : To: [EMAIL PROTECTED] : Subject: Version of Perl : : : I have check out a Perl script on my desktop and it has no : syntax errors. I : used strict to validate the Perl script. I copy the script to my : production machine and now I get a syntax error. I'm : assuming that I have : different version of Perl on both machines. Is there a easy way to : determine Perl versions? Both machines are NT version 4.0, : my desktop is at : SP6.A and the production machine is at SP4. : : Bill Bryan : EDM International : 915-225-2526 Voice : 915-225-2600 Fax : e-mail [EMAIL PROTECTED] : e-mail [EMAIL PROTECTED] (home) : : ___ : Perl-Win32-Users mailing list : [EMAIL PROTECTED] : http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users : ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: parsing blackice csv file
: : i would like to be able to read in a csv file and output it : into html. does anyone have a template type of a script that : could this that would be willing to share it? : It doesn't look like anyone else answered this question, so... CSV should just be a comma-separated-values file, which is pretty much what it sounds like. I believe there is a DBD::CSV (or similar) module that gives you a database API (i.e. DBI) to files in this format, or if the data is relatively simple you may prefer to write your own routine to split each line on a comma character. HTH, --Art ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: parsing blackice csv file
: my @line = split(/\,/,$line); Not necessarily that simple. There could be fields with commas and/or newlines embedded in them, contained within quotation marks. If the OP's data is that complex he may want to consider using the module to parse his data. If it's just simple data with nothing funny going on, then your approach should work. --Art ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users