deep and shallow binding
Hi, Can any one explain me how perl treats this binding? - also i'm little confused about the binding rules for reference environments. Unless we use strict, i guess, the default scope is global - is this right? Any pointers,links will be highly appreciated regards -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Regex help
Huh.. Thanks a ton. I never expected a program. :-)). regards -Ajey On Sun, 16 Jan 2005, Dave Gray wrote: On Sat, 15 Jan 2005 01:25:21 -0800 (PST), Ajey Kulkarni [EMAIL PROTECTED] wrote: I'm trying to match a floating point in ada. They are normal floating points with 2 extra things.(they can or can't come) 1. an underscore is permitted between the digits and 2. An alternate numeric base may be specified surrounding the nonexponent part of the number with pound signs, precided by a base in decimal. Eg: 16#6.a7#e+2, 18.9, Sounds suspiciously like homework, but that's a fun problem. __CODE__ #!/usr/bin/perl use strict; use warnings; my @numbers = ( '16#6.f7#e+2', '18.9', '2#01013#', '16e+2', ); my @valid = (0 .. 9, 'a' .. 'z'); for my $num (@numbers) { my ($base, $n, $exp); if ($num =~ /^(\d+)\#([^\#]*?)\#(?:e\+(\d+))?$/x) { ($base, $n) = ($1, $2); $exp = defined $3 ? $3 : 1; } elsif ($num =~ /^(\d[\d._]*?)(?:e\+(\d+))?$/) { ($base, $n) = (10, $1); $exp = defined $2 ? $2 : 1; } next if not $n; my $invalid = '[^._'.join('',@valid[0..($base-1)]).']'; warn invalid base $base number [$n] detected! ($invalid)\n if $n =~ /$invalid/; print got base $base, num $n, exp $exp\n; } __END__ That should (more than) get you started! HTH, Dave -- 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
Regex help
Hi, I'm trying to match a floating point in ada. They are normal floating points with 2 extra things.(they can or can't come) 1. an underscore is permitted between the digits and 2. An alternate numeric base may be specified surrounding the nonexponent part of the number with pound signs, precided by a base in decimal. Eg: 16#6.a7#e+2, 18.9, I've ([0-9_]+(#[0-9]+\.[0-9a-fA-F]*#e[0-9]*)?) regex to match it, but i'm somwhere goofing up after the dec point. Can any one help me out? regards -A -- 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 monitor a scritp
also,often its easy to forget cron.allow and cron.deny files being updated. Make sure u've right access crontab -e (for user specific) may also help to test ur script locally. May be you should check with the cron/crontab tweakins than Perl list. :) On Tue, 23 Nov 2004, Larsen, Errin M HMMA/IT wrote: -Original Message- From: Mauro [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 23, 2004 3:44 AM To: [EMAIL PROTECTED] Subject: How to monitor a scritp Hi all, I made a script that works fine. When a try to run it in crontab it seems it doesn't work. It makes an empty output log. I checked for correct path in external command I run into script because I know crontab hasn't got any environment variable but pheraps I forgot to check something... How do you suggest me to monitor what it is happening? Does Perl need any explicit environment variables to run in crontab? Thank you Can you show us the meat of your script? Also, the crontab line your using? Maybe we could help you out a little better with that info. --Errin -- 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
perl module - Statistical mean and sd
Hello all, does any1 know the perl module for the same? Also, i want to submit a couple of modules to cpan library. Whats the process to do this? regards ~A. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regexp for ip address
I would love to see the 'HUGE' regex being re-coded using rule based perl 6.0 on Parrot ;-)). The 6.0 regex engine looks like the one of YACC (grammar) based to me. Just a sidenote ~A On Fri, 12 Nov 2004, Ing. Branislav Gerzo wrote: Gunnar Hjalmarsson [GH], on Friday, November 12, 2004 at 00:59 (+0100) contributed this to our collective wisdom: GH What's your definition of a good IP address? Do you care about correct GH DNS, do you care about whether the address is in use? I care about that, if its syntax is correct: 1-255.0-255.0-255.0-255 GH To me, this test comes to mind: GH sub goodIP { gethostbyaddr pack('C4', split /\./, shift), 2 } GH print Good IP address\n if goodIP('11.22.33.44'); after that I can use this, thanks. I don't want use any module for this, GH Why? I have to first extract IP adresses with ports (20-65535) from the source (web, txt...) and ip addr and port could have more then one delimiter, for example ':', ' ', 'port' or they should be in html tables. So after some playing with that I come with: while (TXT) { /^((2[0-5]{2}|1\d{2}|[1-9]\d|[1-9])\.((2[0-5]{2}|1\d{2}|[1-9]\d|\d)\.){2}(2[0-5]{2}|1\d{2}|[1-9]\d|\d))(\s*(port|:|\s|\/td\s*td[^]+)\s*)([2-9]\d|[1-9]\d{2,3}|[1-5]\d{4}|6[0-4]\d{3}|654\d{2}|655[0-2]\d|6553[0-5])$/g; ip = $1; port = $8; push(@ip,$ip,$port); #for example } hm, quite huge regexp, hm ? -- ...m8s, cu l8r, Brano. [Ignorance won't kill you, but it makes you sweat a lot.] -=x=- Skontrolované antivírovým programom NOD32 -- 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: Why doesn't this work?
If you are running this on *NIX box, plain old 'find' command is enough too. ~A On Tue, 9 Nov 2004, Jim wrote: The following subroutine should take an input path (Dir0), process that directory by recursively calling itself on subdirectories or processing any files it contains. The problem I am experiencing is that in the following example file structure it process Dir1 correctly, but after it returns to process the next item in the Dir0, it improperly identifies Dir2 as a file, not a directory. I am sure there is probably a better way of doing this, however, I am somewhat of a newbie to Perl and would like to understand why this code isn't working as I am expecting it to. Do you really want or need to use your own recursive subroutine. Your best bet is probably to use File::Find Read the docs for it. Here are some good links with examples http://perlmonks.thepen.com/217166.html http://www.adp-gmbh.ch/perl/find.html --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/2004 -- 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: how to pass array and varaible
John and Gunnar, Thanks a ton for clarification. ~A On Sun, 7 Nov 2004, John W. Krahn wrote: Gunnar Hjalmarsson wrote: Ajey Kulkarni wrote: Alright, but what is the reason for less time when you pass the ref? I always thought the perl optimizes by sending the ref even if you use a direct array. When you pass an array, Perl *copies* the array elements to @_, so you get two instances of the data in memory. perl stores an alias of each element passed to it into @_ just like foreach does so the *data* is only stored once. $ perl -le' sub my_sub { $_ += 5 foreach @_ } my @x = 10 .. 15; my $x = 55; print @x $x; my_sub @x, $x; print @x $x; ' 10 11 12 13 14 15 55 15 16 17 18 19 20 60 Where can i find more detailed info? perldoc perlsub perldoc perlsub [snip] Any arguments passed in show up in the array @_. Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_[1]. The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments. 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: How to get text after comment
On Mon, 8 Nov 2004, Randy W. Sims wrote: [EMAIL PROTECTED] wrote: Hi, I need to capture whole text after # character in each line from a file.The below script is not working can any one suggest the correct thing plz.. Your regexp: if ($line1 =~ /^#\(.*\)/) ^ - This makes to search ( following a # at the start. I feel you wanted to group and just coded this. /#(.*)$/ ^ Need not be at teh start always (.*)$ anything after and is captured in $1 (till line end). HTH ~A matches any string that: begins with '#' followed by a literal '(' followed by zero or more of any character followed by a literal ')' From your description above, you want something like: /#(.*)$/ which captures anything following a '#' up to the end of the string. Randy. -- 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: how to pass array and varaible
Alright, but what is the reason for less time when you pass the ref? I always thought the perl optimizes by sending the ref even if you use a direct array. Where can i find more detailed info? regards ~A On Sun, 7 Nov 2004, Charles K. Clarkson wrote: Ajey Kulkarni [EMAIL PROTECTED] wrote: : Make sure you pass var first, followed by array. : There is no need to complicate with the array : ref IMHO. Once you are used to working with references, they no longer complicate argument passing. An array reference is always a single scalar while the underlying array may be any length. Passing a reference can take significantly less time. HTH, Charles K. Clarkson -- Mobile Homes Specialist 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
Re: how to pass array and varaible
The varaible number is been appended to the arrya, I want as exactly passed Hmmm...Whenever you pass array AND a variable with array being first, the subroutine takes the variable and appends to array. Your signature MUST BE sub change { my ($var,@arr) = @_; blah blah } Make sure you pass var first,followed by array. There is no need to complicate with the array ref IMHO. regards ~A On Sat, 6 Nov 2004, Anish Kumar K. wrote: #!/usr/bin/perl my @array=(First,second,third); my $menuStr=im; @tempArray=change(@array,$menuStr); foreach (@tempArray) { print \nElement: $_\n; } sub change { my (@nwt,$var)[EMAIL PROTECTED]; print The Varaible is $var \n\n; print Arrays is @nwt \n; @nwt=(23,234,543); return @nwt; } Result: The Varaible is Arrays is First second third im Element: 23 Element: 234 Element: 543 The varaible number is been appended to the arrya, I want as exactly passed Anish - Original Message - From: Edward Wijaya [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Saturday, November 06, 2004 8:52 PM Subject: Re: how to pass array and varaible sub mysub { my ($var, @array) = @_; my @new_array = (); #do sth to @array or $var; return @new_array; } read - perldoc perlsub Regards, Edward WIJAYA On Sat, 6 Nov 2004 12:48:26 +0530, Anish Kumar K. [EMAIL PROTECTED] wrote: Hi I want to pass a array and and a varaible to a subroutine and then some processing will be done at the subtroutine and the array should be returnedPlease help me in trying to figure out... Thanks Anish -- 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Multi Line text processing
my $txt = do { local $/; FILE }; Just on a side note, has any1 tried to get the MAX FILE SIZE that can be slurped into a scalar variable? Is there any limit? Where can i get such info?? Regards ~A On Mon, 1 Nov 2004, Gunnar Hjalmarsson wrote: Anish Kumar K. wrote: I want to replace a text from a file say a.txt. a.txt contains line1: this is line 2: a line 3: apple I wanted to replace to this is an orange.. When I see perl change.pl FILENAME it shld change all the occurence of this is a apple to this is an orange. Not that this search text can be split in multilines. Do perl have some inbulit functions to do the same. The s/// operator (see perldoc perlop) is a suitable tool for doing that. Since you need to search over several lines, it's probably best to slurp the file as one single string into a scalar variable: my $txt = do { local $/; FILE }; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Windows - Unix communication using perl
Howdy, this is more descriptive qn than a programming. I want to try first before i get some errs/doubts. I would like to do something like rexec/rsh from a windows (client) to Unix machine. What is the best way to approach this problem? IO::Socket ,may not be of help coz that requires server to be running. Here i would like to start a process on the server triggered by Windows-client. Any pointers will be of great help Thanks a ton Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Windows - Unix communication using perl
i feel net::rexec module should help me out. Thanks. ~A On Mon, 1 Nov 2004, Chasecreek Systemhouse wrote: On Mon, 1 Nov 2004 14:00:37 -0800 (PST), Ajey Kulkarni [EMAIL PROTECTED] wrote: I would like to do something like rexec/rsh from a windows (client) to Unix machine. What is the best way to approach this problem? IO::Socket ,may not be of help coz that requires server to be running. Here i would like to start a process on the server triggered by Windows-client. You will need some type of server running on the remote, um, server. Maybe Apache or a variant of HTTP? Search CPAN for POE, -- WC -Sx- Jones http://youve-reached-the.endoftheinternet.org/ -- 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: Append on top
while (read OLDFILE, $buff, 8*1024); A quick qn. :) Y is 8*1024 being mentioned here? Are you just word-aligning or something else? regards -Ajey On Fri, 29 Oct 2004, Jenda Krynicky wrote: From: [EMAIL PROTECTED] This is the way I would do it, however my code has been subject to criticism more that once in the past :) open (FILE, myfile.dat) or die; @file = FILE; close (FILE); $new_data = This is my new line that I am going to put at the top\n; unshift (@file, $new_data); open (FILE, myfile.dat) or die; print FILE @file; close (FILE); :-) This is definitely a workable solution, there are just a few things to keep in mind. 1)This would mean that the whole file is read into the memory. 2)This would force Perl to search for end-of-lines and create an array. 3) You open the file in text mode in both cases. This may change the type of newlines in the file! So it's fine for small files, but not so great for bigger ones. If you want something more efficient you might try something like this: open NEWFILE, '', 'myfile.dat.tmp' or die Can't create myfile.dat.tmp: $^E\n; print NEWFILE the new stuff to put on top\n; ... open OLDFILE, '', 'myfile.dat' or die Can't open the original file myfile.dat: $^E\n; binmode(OLDFILE); binmode(NEWFILE); my $buff; print NEWFILE $buff while (read OLDFILE, $buff, 8*1024); close NEWFILE; close OLDFILE; rename 'myfile.dat.tmp' = 'myfile.dat'; Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- 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: each character in a string
It will... #!/usr/bin/perl my $var = -- hellohowareyou-; $_ = $var; while (/(.)/g) { # . is never a newline here # do something with $1 if($1 eq '-') { printf HELLO; } else { printf HI; } } On Fri, 29 Oct 2004 [EMAIL PROTECTED] wrote: Hi All, I have to write a code wherein I have to access each character in a string and compare it with '-' $_ = $seq1[0]; while(/./g) { if($1 eq '-') { $res1[0] .= '-'; } else { $res1[0] = A; } } I have initialised $_ with the string in which I have to search. Now I know that the while loop will read each and every character in the string. I just need to get that character read to make the comparison. I know $1 doesnt work because it is not :) Where is the value returned or how can I assign a variable the value of the condition in the while loop ? Thanks, Manas. -- 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: each character in a string
Also, Mastering Regular EXpressions - Orielly book gives real nice insight about this. I'm still learning PERL...Sigh! ~A On Fri, 29 Oct 2004, Gunnar Hjalmarsson wrote: [EMAIL PROTECTED] wrote: I have to write a code wherein I have to access each character in a string and compare it with '-' $_ = $seq1[0]; while(/./g) { if($1 eq '-') { $res1[0] .= '-'; } else { $res1[0] = A; } } I have initialised $_ with the string in which I have to search. Now I know that the while loop will read each and every character in the string. I just need to get that character read to make the comparison. I know $1 doesnt work because it is not :) Where is the value returned or how can I assign a variable the value of the condition in the while loop ? As Ajey showed, $1 does work provided that you use capturing parentheses, or you can use $ (but read the warning in perldoc perlre if you consider the latter). -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
File read qn
howdy!! I've a code snipped that reads the file into array. The file is a comma separated file. I want to say get 4th column of the whole file in an array. @lines = LIB::readFile($opt{f}); My @lines has the whole comma separated file. I would like to now get the 4th column of whole file (using @lines) in an array. I can do this by parsing the @lines again ,split() and get each array element,but this may be slow. Is there better way to achive this?? Thanks a ton, Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: File read qn
David,Thanks much. I'll give it a shot and comeup with the code. This is a new learning to me today :) regards -Ajey On Sat, 23 Oct 2004, David le Blanc wrote: On Fri, 22 Oct 2004 20:13:05 -0700 (PDT), Ajey Kulkarni [EMAIL PROTECTED] wrote: howdy!! I've a code snipped that reads the file into array. The file is a comma separated file. I want to say get 4th column of the whole file in an array. @lines = LIB::readFile($opt{f}); My @lines has the whole comma separated file. I would like to now get the 4th column of whole file (using @lines) in an array. I can do this by parsing the @lines again ,split() and get each array element,but this may be slow. This is difficult to optimise because perl doesn't have any way to pre-index a data structure in preparation for extracting data. Keep down the work by avoiding loop variables, iterate using internal functions and avoid splitting more than necessary.. Example: @lines = LIB::readfile(...); $col = 4; @coldata = map { (split(,,$_,$col+1))[$col] } @lines; Here, each element is spit into '$col + 1' columns, after all why split a data stream into 50 elements when you only want the fourth.. The result of split is treated as an array, and the particular column [$col] is extracted. The result of the 'MAP' call is an array containing the fourth column of every line. Now, if you are going to do this more than once, you would split the whole file first, and then use two separate column extractions. Example: @lines = LIB::readfile(...); # Convert array of SCALARS to array of references to arrays of SCALARS. @line_data = map { [ split( ,, $_ ) ] } @lines; # Get col 3 @col_3 = map { $_-[3] } @line_data; # Get col 7 @col_7 = map { $_-[7] } @line_data; # - I use the $_-[x] syntax here because $$_[x] is ugly. HTH Cheers. Is there better way to achive this?? Thanks a ton, Ajey -- 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
Reg ex : tabs/spaces
Howdy, I would like to remove all the spaces tabs from a variable. my($word) =Detail Design Activity Included ; $word =~ s/^\s*(\D*)\s*$/$1/; printf word=$word#\n; word=Detail Design Activity Included# the above stuff is the output and i'm stil not able to get the trailing blanks. After i'm done with this,. how can i remove the intermediate blanks which occur?? Is it best to store in a array and then join??? regards -ajey -- 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 ex : tabs/spaces
Thanks a ton Gunnar, How about the intermediate blanks? Is there a way to recursively take all blanks/tabs that occur?? word=Detail Design Activity Included# I would like to remove the blanks here.. TIA -Ajey On Sun, 17 Oct 2004, Gunnar Hjalmarsson wrote: Ajey Kulkarni wrote: I would like to remove all the spaces tabs from a variable. No, you wouldn't. You would like to remove possible whitespace from the beginning and end of a string. my($word) =Detail Design Activity Included ; $word =~ s/^\s*(\D*)\s*$/$1/; It's best done using two substitutions: $word =~ s/^\s+//; $word =~ s/\s+$//; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reg ex : tabs/spaces
One more extension to this qn. #snippet to replace all the ,, with ,NEW, my($word) =Detail Design Activity Included ,-1,0 ,hello,ajey ; $word =~ s/\s+//g; $word =~ s/,,/,NEW,/gc; printf word=$word#\n; after removing the blanks ,if there are any ,, i would like to insert a NEW word there. So my regex, does this but its doing it partially. word=DetailDesignActivityIncluded,NEW,,NEW,,-1,0,hello,ajey# ^^^ ^^^ These two are again not matched. I checked the options for c Do not reset search position on a failed match when /g is in effect. g Match globally, i.e., find all occurrences. i Do case-insensitive pattern matching. m Treat string as multiple lines. o Compile pattern only once. s Treat string as single line. x Use extended regular expressions. But, this is little confusing to me. I know its greedy approach while matching patterns,but here its missing something. Where am i wrong?? My aim to have a NEW inserted btwn every ,, Regards -Ajey On Sun, 17 Oct 2004, Gunnar Hjalmarsson wrote: Ajey Kulkarni wrote: Gunnar Hjalmarsson wrote: Ajey Kulkarni wrote: I would like to remove all the spaces tabs from a variable. No, you wouldn't. You would like to remove possible whitespace from the beginning and end of a string. my($word) =Detail Design Activity Included ; $word =~ s/^\s*(\D*)\s*$/$1/; It's best done using two substitutions: $word =~ s/^\s+//; $word =~ s/\s+$//; Thanks a ton Gunnar, How about the intermediate blanks? Is there a way to recursively take all blanks/tabs that occur?? Did you really want that? In that case I misunderstood you; Please disregard my previous suggestion. To actually remove *all* whitespace, you can simply do: $word =~ s/\s+//g; Read about the /g modifier in the description of the s/// operator in perldoc perlop. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
File parsing
Hi, I'm parsing a file line by line. The fine is a comma separated file. I would like to search replace or simply DELETE a column(field). 00018/11/1988 Development Government/Defense USA CSCIGROUND STATION UPGRADE Military Ground Command/Control 0 0 0 Say the line above is separated by commas,and i would like to parse the same. I'm doing this using split(). Now that depending on the user input, i want to search/replace or simply delete the field (or column). What is the best way to this. (Fastest??). Regards -Ajey -- 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 do I get rid of
if you open the file in vi,say :%s/ctrl-v ctrl-p//g You can check $line =~ s/ctrl-v ctrl-p//g; Mainly ^ = ctrl-v P = ctrl-p regards -Ajey On Thu, 23 Sep 2004, William Martell wrote: Hi All, This is in a text file that I am working with. I am trying to remove it, but it seems to be a different character in different places throughout the text, even though to me, when viewed in Textpad text editor, it looks the same. Is there a special hex code or something that I can use to strip all of these from the text file? Thanks Will -- 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: XMLin() not finding XML::SAX or XML::Parser modules Problem
I installed the expat libs,but the cpan shell is now asking for EXPATLIBPATH and EXPATINCPATH. It says perl Makefile.PL path_to_libraries Now,how do i specify these paths for XML::Module installation?? Where is this Makefile.PL file? Regards again -Ajey On Thu, 23 Sep 2004, Chris Devers wrote: Please send all replies to the list, not me directly. Thanks. On Thu, 23 Sep 2004, Ajey Kulkarni wrote: Thanks a bunch Chris. I FORCED the pms to be copied. I'll try to install this and get it running. It usually isn't a good idea to force an install unless you understand what the error you're getting means and are confident that in a given case it can be safely ignored. In this case, the README file is clear that you need to have one of the two modules you noted in order for things to work. If you skip that step, then, well, things won't work. On the bright side, you probably don't have to reinstall XML::Simple; once the support module[s] is/are in place, XMLin(...) should work. Or at least that's what it seems like will happen... -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
XMLin() not finding XML::SAX or XML::Parser modules Problem
Hi, XMLin() requires either XML::SAX or XML::Parser at line number blah blah. I actually copied these two perl modules in the right place but still then my script is not able to find these.(in @INC). I'm trying to call this XMLin() function from another perl module. Am i missing anything here? Any pointers? Thanks a ton -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl modules path related
hi, I've a perl script which uses a perl module located in /tools/tools/perl/lib. If i want to change this path to say /tmp/perlNew/lib and make the script to fetch the new /tmp/perlNew/lib path. How can i do this?? TIA -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: String concatenation qn
Thanks a ton to all. On Sat, 24 Jan 2004, drieux wrote: On Jan 23, 2004, at 5:24 PM, wolf blaum wrote: For Quality purpouses, Ajey Kulkarni 's mail on Saturday 24 January 2004 17:52 may have been monitored or recorded as: i would like to quickly append a string to a variable. open NEWFH, $filename.new or die new procmailrc err; where $filename has /tmp/xyz Anything really silly here?? Nothing I didnt do wrong at least a thousand times: open NEWFH, $filename..new or die new procmailrc err; [..] forgive me for being 'pedantic' but given the sequence foreach my $filename (@list_of_file_names) { open(NEWFH, ${filename}.new ) or die new $filename err:$!; } One has 'less ambiguity' using the curley braces around the variable name so that it will KNOW without a doubt that one really means that to be the variable should suffice - It really becomes important when you want to concatenate without things like a . between tokens foreach my $start (@entree) { foreach my $phrase (@list_of_sillies) { my $freak = ${start}Buzz${phrase}here; rhetorical_devices($freak); } } -- 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
String concatenation qn
hi,. i would like to quickly append a string to a variable. Suppose $filename has /tmp/xyz after appending i want to get $filename as /tmp/xyz.NEW. I'm getting a ? for a . (period). I'm doing something like open NEWFH, $filename.new or die new procmailrc err; where $filename has /tmp/xyz Anything really silly here?? regards -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
qn about the reg expression.
hi , whenever 1 matches something in regular expression,where the 'MATCHED EXPRESSION' be stored? will this be stored in $_ variable where can i find more info about this?? tia -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
hi..
happy new year to all,.. i've a qn.,:) i want to 'insert' an escape character for every '[' ']' i will find in a variable.. Suppose $temp has a word which might contain [ and/or ]. Eg: if $temp has hello] the modified temp should have hello\] if $value has [hello] i want the result to be \[hello\]. Is there a quick one line regex to do this? i'm able to match the presence of [ ] if( (/\[/)|(/\]/) ){ my $value = $_; $value =~ s/\[/\\\[/; $value =~ s/\]/\\\]/; print $value; } Kinda doing the stuff,but i just checkign out a 1 liner reg-ex. regards -ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: hi..
thanks Charles.I will give the ryt subject next time. On Fri, 2 Jan 2004, Charles K. Clarkson wrote: Ajey Kulkarni [EMAIL PROTECTED] wrote: : Subject: hi.. sarcasm Great subject. So much better than Need help with regex or Need to escape []. Always keep us guessing. /sarcasm : i want to 'insert' an escape character for every '[' ']' : i will find in a variable.. : : Suppose $temp has a word which might contain [ and/or ]. : Eg: if $temp has hello] : the modified temp should have hello\] : : if $value has [hello] i want the result to be \[hello\]. : : Is there a quick one line regex to do this? : i'm able to match the presence of [ ] : if( (/\[/)|(/\]/) ){ : my $value = $_; : $value =~ s/\[/\\\[/; : $value =~ s/\]/\\\]/; : print $value; : } A one-liner is not necessarily better. You might want to test. The substitution operator has a pattern on the left side and a replacement string on the other. According to 'perlop' it takes this form: s/PATTERN/REPLACEMENT/egimosx Let's take a look at your phrase: s/\[/\\\[/ The PATTERN is '\[' and the REPLACEMENT is \\\[. I put the REPLACEMENT in double quotes because that is how it is most commonly interpolated. To print '\[' we need \\[ on the REPLACEMENT side. The PATTERN side views '[', and ']' as special characters. So we need to escape them or we need to use some other means to describe them. To look for more than one we can place them in a character class: [\[\]] or as [\][] then capture the one we match: ([\][]). s/([\][])/\\$1/ We could also avoid the character class and use: s/(\]|\[)/\\$1/ To capture multiple instances in the line we add 'g'. s/([\][])/\\$1/g And to make it easier to read we add x: $value =~ s/ # start substitution ( # capture match in $1 [\][] # character class for [ and ] ) # end capture /\\$1/gx; # replace with \[ or \] globally Having said all this. I would still prefer Rob's solution with two separate regexes in a 'foreach'. 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
some doubt
hi, How can i rename a file and check the size of file using perl? Also is there a way to call unix commands/system calls from perl?(Say i want to fstat() on a file and grab the stat struct results). Is there any way?? TIA -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
1 doubt.
perl t.pl Name main::FH used only once: possible typo at t.pl line 6. cat t.pl #!/usr/bin/perl use strict; use warnings; open FH, out.dat; Why am i getting this warning? When i remove the warnings,this goes off? Is there any problem if i not include use warnings line? Quick reply is highly appreciated regards -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
2nd doubt.
HI again. I'm tryign to modify the .procmailrc file Initially the file looks liek this -- :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0 | dmail +INBOX the file after modificatin should look like :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 wB * ^X-Spam-Status: Yes | dmail +mail/junk :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 w | dmail +INBOX This is my first realtime use of perl,and i'm kinda stomped. I'm able to read each line in the procmailrc file,but just ened to parse the (line by line) and modify the contents. Help required. -Aj -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response