CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
substitution and print

 



uatt
User

Aug 20, 2002, 6:48 AM

Post #1 of 7 (1374 views)
substitution and print Can't Post

This is the format inside array

13637 H01 156 FIFTH STREET, NNN, TIII OOO, SOME WHERE.

..........

.............


I like to extract the beginning numbers i.e. 13637

This is my try




Code
  

foreach(@array)
{$_ =~ s/^(d+).+H.*/$1/g;
print "$_<br>\n";}



Seemingly, I cannot extract it and it just print out same line

So, where I am getting wrong...Thanks


fashimpaur
User / Moderator

Aug 20, 2002, 7:45 AM

Post #2 of 7 (1371 views)
Re: [uatt] substitution and print [In reply to] Can't Post

uatt,

Are you trying to remove the starting digits and print the whole line or do you
want to find lines that start with digits and print the whole line?

If you want to remove the starting digits, try this:

Code
   
foreach (@array){
s/^(\d+)//;
print "$_\n";
}

If you want to print lines without removing digits, try this:

Code
   
foreach(@array){
print "$_\n" if /^(\d+)/;
}

Hope this helps. If not, post back more detail.

Good Luck,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


uatt
User

Aug 20, 2002, 7:45 AM

Post #3 of 7 (1370 views)
Re: [uatt] substitution and print [In reply to] Can't Post


Code
foreach(@array)  
{$_ =~ s/\s+H.*//g;
print "$_<br>\n";}




davorg
Thaumaturge / Moderator

Aug 20, 2002, 7:58 AM

Post #4 of 7 (1369 views)
Re: [uatt] substitution and print [In reply to] Can't Post


Code
foreach (@array) { 
print "$1<br />\n" if /^(\d+)/;
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


uatt
User

Aug 20, 2002, 8:48 AM

Post #5 of 7 (1367 views)
Re: [davorg] substitution and print [In reply to] Can't Post

Thank you all


Code
  

print "$1<br />\n" if /^(\d+)/;



This I know...

But why this not work


Code
  

$_ =~ s/^(d+).+H.*/$1/g;



davorg
Thaumaturge / Moderator

Aug 20, 2002, 8:55 AM

Post #6 of 7 (1365 views)
Re: [uatt] substitution and print [In reply to] Can't Post

Because you've got "d" where you should have "\d"?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


uatt
User

Aug 20, 2002, 9:01 AM

Post #7 of 7 (1364 views)
Re: [davorg] substitution and print [In reply to] Can't Post

yes, Very simple mistake...

thanks..

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives