if (/^$date\s+(.+)/)

Discussion in 'Perl Misc' started by April, Oct 29, 2008.

  1. April

    April Guest

    {
    printf "%2d. ", $count;
    print "$1\n";
    }

    what would be true for /^$date\s+(.+)/? \s+ matches one or more white
    spaces, and (.+) matches the rest?
     
    April, Oct 29, 2008
    #1
    1. Advertising

  2. April

    Tim Greer Guest

    April wrote:

    >
    > {
    > printf "%2d. ", $count;
    > print "$1\n";
    > }


    ^^^^^^^^^^

    Is the above supposed to relate to your question?

    > what would be true for /^$date\s+(.+)/? \s+ matches one or more white
    > spaces, and (.+) matches the rest?


    ..+ matches anything (one or more characters) after the start of the line
    ^ and whatever $date is, one or more white spaces and then captures
    whatever follows it. You might want to be more specific if you want to
    match up to the end of the line $ or include new lines, or only match
    up to a certain length or character, etc. So, yes and no, depending.
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
     
    Tim Greer, Oct 29, 2008
    #2
    1. Advertising

  3. April

    April Guest

    On Oct 29, 1:58 am, Tim Greer <> wrote:
    > April wrote:
    >
    > >             {
    > >                 printf "%2d. ", $count;
    > >                 print "$1\n";
    > >             }

    >
    > ^^^^^^^^^^
    >
    > Is the above supposed to relate to your question?
    >
    > > what would be true for /^$date\s+(.+)/?  \s+ matches one or more white
    > > spaces, and (.+) matches the rest?

    >
    > .+ matches anything (one or more characters) after the start of the line
    > ^ and whatever $date is, one or more white spaces and then captures
    > whatever follows it.  You might want to be more specific if you want to
    > match up to the end of the line $ or include new lines, or only match
    > up to a certain length or character, etc.  So, yes and no, depending.
    > --
    > Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    > Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    > and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
    > Industry's most experienced staff! -- Web Hosting With Muscle!


    thanks Tim .. then what would be true here, something started with
    $date exists?
     
    April, Oct 29, 2008
    #3
  4. Tim Greer wrote:
    > April wrote:
    >
    >> {
    >> printf "%2d. ", $count;
    >> print "$1\n";
    >> }

    >
    > ^^^^^^^^^^
    >
    > Is the above supposed to relate to your question?


    It's probably cut and pasted from the assignment sheet.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
     
    Josef Moellers, Oct 29, 2008
    #4
  5. April

    April Guest

    On Oct 29, 8:39 am, Josef Moellers <josef.moell...@fujitsu-
    siemens.com> wrote:
    > Tim Greer wrote:
    > > April wrote:

    >
    > >>             {
    > >>                 printf "%2d. ", $count;
    > >>                 print "$1\n";
    > >>             }

    >
    > > ^^^^^^^^^^

    >
    > > Is the above supposed to relate to your question?

    >
    > It's probably cut and pasted from the assignment sheet.
    >
    > --
    > These are my personal views and not those of Fujitsu Siemens Computers!
    > Josef Möllers (Pinguinpfleger bei FSC)
    >         If failure had no penalty success would not be a prize (T..  Pratchett)
    > Company Details:http://www.fujitsu-siemens.com/imprint.html


    yes, that is the block to be executed, depending on the if test
    result ..
     
    April, Oct 29, 2008
    #5
  6. April <> wrote:
    >
    > {
    > printf "%2d. ", $count;
    > print "$1\n";
    > }


    ???

    >what would be true for /^$date\s+(.+)/? \


    You question is confusing. Did you mean to ask: Which strings are
    matched by that RE?

    Answer to that question:
    Any string, that
    - starts with
    - whatever is matched by the RE stored in $date
    and then

    >\s+ matches one or more white

    -has at least one white space

    >spaces, and (.+) matches the rest?

    - and then at least one other character

    jue
     
    Jürgen Exner, Oct 29, 2008
    #6
  7. April

    April Guest

    On Oct 29, 10:38 am, Glenn Jackman <> wrote:
    > At 2008-10-28 11:17PM, "April" wrote:
    >
    > >              if (/^$date\s+(.+)/)
    > >              {
    > >                  printf "%2d. ", $count;
    > >                  print "$1\n";
    > >              }

    >
    > >  what would be true for /^$date\s+(.+)/?

    >
    > That depends on the current line ($_) and the value of $date.
    >
    > You need to provide more info if you expect to receive any help.  
    >
    > --
    > Glenn Jackman
    >     Write a wise saying and your name will live forever. -- Anonymous


    I'm looking for the meaning of that test, not an actual answer in the
    program context.
     
    April, Oct 29, 2008
    #7
  8. April

    April Guest

    On Oct 29, 11:59 am, Jürgen Exner <> wrote:
    > April <> wrote:
    >
    > >            {
    > >                printf "%2d. ", $count;
    > >                print "$1\n";
    > >            }

    >
    > ???
    >
    > >what would be true for /^$date\s+(.+)/?  \

    >
    > You question is confusing. Did you mean to ask: Which strings are
    > matched by that RE?
    >
    > Answer to that question:
    > Any string, that
    > - starts with
    > - whatever is matched by the RE stored in $date
    > and then
    >
    > >\s+ matches one or more white

    >
    > -has at least one white space
    >
    > >spaces, and (.+) matches the rest?

    >
    > - and then at least one other character
    >
    > jue


    my question should be restated as what makes the if test true, if (/^
    $date\s+(.+)/)?
     
    April, Oct 29, 2008
    #8
  9. April <> wrote:

    if (/^$date\s+(.+)/)

    >my question should be restated as what makes the if test true, if (/^
    >$date\s+(.+)/)?


    Ok, that is easy. The condition is true if and only if the regular
    expression /^$date\s+(.+)/ matches the text content of $_.

    jue
     
    Jürgen Exner, Oct 29, 2008
    #9
  10. April

    April Guest

    On Oct 29, 12:46 pm, Jürgen Exner <> wrote:
    > April <> wrote:
    >
    >                 if (/^$date\s+(.+)/)
    >
    > >my question should be restated as what makes the if test true, if (/^
    > >$date\s+(.+)/)?

    >
    > Ok, that is easy. The condition is true if and only if  the regular
    > expression /^$date\s+(.+)/ matches the text content of $_.
    >
    > jue


    k thank you Jue and everyone I think with this and the explanation of
    the re/pattern, I'm all set and thanks again.
     
    April, Oct 29, 2008
    #10
  11. April

    Dr.Ruud Guest

    April schreef:

    > /^$date\s+(.+)/?


    You probably need to change "$date" to "\Q$date\E".
    See `perldoc -f quotemeta`.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Oct 29, 2008
    #11
  12. April

    Guest

    On Tue, 28 Oct 2008 20:17:09 -0700 (PDT), April <> wrote:

    >
    > {
    > printf "%2d. ", $count;
    > print "$1\n";
    > }
    >
    >what would be true for /^$date\s+(.+)/? \s+ matches one or more white
    >spaces, and (.+) matches the rest?


    Yes, is date variable? It is part of the regex.
    What is the result if

    $date = "12/25/2008";
    $_ = "12/25/2008
    is an important date
    on the calendar.";
     
    , Oct 30, 2008
    #12
    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. Matt
    Replies:
    1
    Views:
    609
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,279
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    520
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    724
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    408
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page