Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: find, then store functions into array problem

by pfaut (Priest)
on May 04, 2003 at 22:57 UTC ( #255531=note: print w/replies, xml ) Need Help??


in reply to find, then store functions into array problem

This appears to do what you need.

#!/usr/bin/perl -w use strict; while (my $righteq = <DATA>) { my @remaining = $righteq =~ /([a-z]\^(?:[a-z]|\([a-z][+-]\d+(?:\.\ +d+)?\)))/g; print '$remaining[',$_,'] is ',$remaining[$_],$/ for 0..$#remainin +g; } __DATA__ +++-+++t^n+++f^n+e^(t-123.22) t^n+--++-+f^n++e^(t-123.22)++ +++++---+t^n+f^n+++e^(t-123.22)-

Output:

$remaining[0] is t^n $remaining[1] is f^n $remaining[2] is e^(t-123.22) $remaining[0] is t^n $remaining[1] is f^n $remaining[2] is e^(t-123.22) $remaining[0] is t^n $remaining[1] is f^n $remaining[2] is e^(t-123.22)

Update: changed to read into $righteq instead of using $_.

90% of every Perl application is already written.
dragonchild

Replies are listed 'Best First'.
Re: Re: find, then store functions into array problem
by hideki-san (Initiate) on May 04, 2003 at 23:28 UTC
    What do I change in your code snippet if the raw data is $righteq, not __DATA__?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://255531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-05-09 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (101 votes). Check out past polls.

    Notices?