substituion

Discussion in 'Perl' started by jared in ecs, Oct 23, 2003.

  1. jared in ecs

    jared in ecs Guest

    i'm trying to find the price in a page source and my substition seems
    not to work?
    $dump =~ s/.+?Price:\s+\$([0-9][0-9].[0-9][0-9]).+/$1/s;

    does anyone have a suggestion as to why it prints the whole dump file
    w/o seeming to substitute the price in.
     
    jared in ecs, Oct 23, 2003
    #1
    1. Advertising

  2. jared in ecs wrote:
    > i'm trying to find the price in a page source and my substition
    > seems not to work?


    If you are trying to _find_ something, why are you trying to _substitute_?

    > $dump =~ s/.+?Price:\s+\$([0-9][0-9].[0-9][0-9]).+/$1/s;


    You haven't told us what $dump contains, but I imagine that it may
    result in everything but the price being stripped from $dump under
    certain conditions.

    This is another approach:

    my ($price) = $dump =~ /Price:\s+\$(\d+\.\d+)/;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 23, 2003
    #2
    1. Advertising

  3. jared in ecs

    Jim Gibson Guest

    In article <>, jared in
    ecs <> wrote:

    > i'm trying to find the price in a page source and my substition seems
    > not to work?
    > $dump =~ s/.+?Price:\s+\$([0-9][0-9].[0-9][0-9]).+/$1/s;
    >
    > does anyone have a suggestion as to why it prints the whole dump file
    > w/o seeming to substitute the price in.


    "seems no to work" is a little vague. What is in $dump before the
    substitution operator is applied? My guess is that your pattern is in
    fact not matching, and no substitution is done, leaving the original
    string in $dump. Perhaps your page doesn't have a space between
    "Price:" and the price. If so, use 'Price:\s*$', etc. instead.

    Try posting a complete (brief) program for better answers.

    BTW, this newsgroup is defunct. Try comp.lang.misc.perl in the future.
     
    Jim Gibson, Oct 23, 2003
    #3
  4. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    (jared in ecs) wrote in
    news::

    > i'm trying to find the price in a page source and my substition seems
    > not to work?
    > $dump =~ s/.+?Price:\s+\$([0-9][0-9].[0-9][0-9]).+/$1/s;
    >
    > does anyone have a suggestion as to why it prints the whole dump file
    > w/o seeming to substitute the price in.


    The above expression cannot print anything at all -- the s/// operator
    doesn't print. What do you mean by "it prints"? Some other part of your
    script is printing, that's what. Do you expect people here to be psychic?
    What is in $dump before the above statement? We don't know your data.

    In the future, please post questions to comp.lang.perl.misc; that's the
    newsgroup for general perl questions. Comp.lang.perl is a defunct
    newsgroup.

    - --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBP5ku3GPeouIeTNHoEQJmfgCfZHl6dHOE5eg4/mUHOySB8ElIVOkAoIEi
    4GylIMM+2M8B7We8jWQ0y75R
    =6Tpo
    -----END PGP SIGNATURE-----
     
    Eric J. Roode, Oct 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David M. Aldridge
    Replies:
    0
    Views:
    388
    David M. Aldridge
    Jan 17, 2004
  2. Horacius ReX

    non-uniform string substituion

    Horacius ReX, Feb 13, 2008, in forum: Python
    Replies:
    2
    Views:
    273
    7stud
    Feb 14, 2008
Loading...

Share This Page