Help needed for perl rookie

Discussion in 'Perl Misc' started by GRLCOPM, Dec 27, 2004.

  1. GRLCOPM

    GRLCOPM Guest

    I am new to perl, but so far have had decent success in writing/modifying
    code to do what I want to do. However I am stuck trying to modify the
    following code. I am sure the solution is quite simple, but I can't
    completely figure out what this piece of code does. I think it is just
    matching up a data pattern but this is an area I am unfamiliar with.

    All I want to do is change the format of the data file from example #1 to
    example #2 and need this section of code to work with the new format. I
    would be grateful for any help provided in understanding what this piece of
    code does and suggestions on the modification needed.

    If more information or a larger chunk of the code is needed please let me
    know and I will provide.

    EXAMPLE #1 - Current format of data file:
    0000000050 20041227 0000000003 'my-page.shtml'
    0000000054 20041227 0000000004 'another-page.shtml'
    0000000020 20041227 0000000003 'yet-another-page.shtml'

    EXAMPLE #2 - New format of data file:
    0000000050|20041227|0000000003|my-page.shtml
    0000000054|20041227|0000000004|another-page.shtml
    0000000020|20041227|0000000003|yet-another-page.shtml

    Current code that reads original data format:

    &LockOpen (COUNT,"$AccessFile");
    $location = tell COUNT;
    while ($line = <COUNT>) {
    if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+) '(\S+)'$/)) {
    if ($uri eq $doc_uri) {
    last;
    }
    }
    last if ($uri eq $doc_uri);
    $location = tell COUNT;
    $acc = 0;
    $dayacc = 0;
    }


    Thanks!

    PM
     
    GRLCOPM, Dec 27, 2004
    #1
    1. Advertising

  2. GRLCOPM

    Guest

    GRLCOPM wrote:
    > I am new to perl, but so far have had decent success in

    writing/modifying
    > code to do what I want to do. However I am stuck trying to modify the
    > following code. I am sure the solution is quite simple, but I can't
    > completely figure out what this piece of code does. I think it is

    just
    > matching up a data pattern but this is an area I am unfamiliar with.
    >
    > All I want to do is change the format of the data file from example

    #1 to
    > example #2 and need this section of code to work with the new format.

    I
    > would be grateful for any help provided in understanding what this

    piece of
    > code does and suggestions on the modification needed.
    >
    > If more information or a larger chunk of the code is needed please

    let me
    > know and I will provide.
    >
    > EXAMPLE #1 - Current format of data file:
    > 0000000050 20041227 0000000003 'my-page.shtml'
    > 0000000054 20041227 0000000004 'another-page.shtml'
    > 0000000020 20041227 0000000003 'yet-another-page.shtml'
    >
    > EXAMPLE #2 - New format of data file:
    > 0000000050|20041227|0000000003|my-page.shtml
    > 0000000054|20041227|0000000004|another-page.shtml
    > 0000000020|20041227|0000000003|yet-another-page.shtml
    >


    looks like you are replacing the spaces after the numbers with a '|'
    and removing the single quotes.

    s/(\d+)\s/$1|/g;
    s/'//g;

    maybe

    > Current code that reads original data format:
    >
    > &LockOpen (COUNT,"$AccessFile");
    > $location = tell COUNT;
    > while ($line = <COUNT>) {
    > if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+)

    '(\S+)'$/)) {
    > if ($uri eq $doc_uri) {
    > last;
    > }
    > }
    > last if ($uri eq $doc_uri);
    > $location = tell COUNT;
    > $acc = 0;
    > $dayacc = 0;
    > }
    >
    >
    > Thanks!
    >
    > PM
     
    , Dec 27, 2004
    #2
    1. Advertising

  3. GRLCOPM

    GRLCOPM Guest


    > From:
    > Organization: http://groups.google.com
    > Newsgroups: comp.lang.perl.misc
    > Date: 27 Dec 2004 14:17:37 -0800
    > Subject: Re: Help needed for perl rookie
    >
    >
    > looks like you are replacing the spaces after the numbers with a '|'
    > and removing the single quotes.
    >
    > s/(\d+)\s/$1|/g;
    > s/'//g;
    >


    Yes, that is how I have changed the format of the data file. Replaced the
    spaces with | and removed the single quotes from the last item on the line.

    Can someone please explain what the the following line of code does and what
    the replacement would be?

    if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+) '(\S+)'$/)) {

    Thanks

    Patrick
     
    GRLCOPM, Dec 27, 2004
    #3
  4. GRLCOPM

    Jim Keenan Guest

    GRLCOPM wrote:
    > I am new to perl,



    For your future reference: Read the posting guidelines for this Usenet
    news group: http://mail.augustmail.com/~tadmc/clpmisc.shtml

    As the guidelines advise, put your real Perl subject in the "Subject"
    line. There's no need to apologize for being a rookie provided you make
    a genuine effort to solve the problem yourself prior to posting. But
    the fact that you're new to Perl, should you wish to include it, is best
    included in the body of your posting. Don't take up valuable Net real
    estate by wasting it on the Subject line. HTH.

    Jim Keenan
     
    Jim Keenan, Dec 28, 2004
    #4
  5. GRLCOPM

    GRLCOPM Guest


    > From: Jim Gibson <>
    > Organization: Newsfeed.com http://www.newsfeeds.com 100,000+ UNCENSORED
    > Newsgroups.
    > Newsgroups: comp.lang.perl.misc
    > Date: Mon, 27 Dec 2004 15:05:04 -0800
    > Subject: Re: Help needed for perl rookie
    >
    > In article <BDF5CC8C.30353%>, GRLCOPM
    > <> wrote:
    >
    >>
    >> Yes, that is how I have changed the format of the data file. Replaced the
    >> spaces with | and removed the single quotes from the last item on the line.
    >>
    >> Can someone please explain what the the following line of code does and what
    >> the replacement would be?
    >>
    >> if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+) '(\S+)'$/)) {

    >
    > Starting from the inner =~ operator and working outwards:
    >


    Thanks Jim!

    At first I missed your reply this morning so please excuse my re-post of the
    question.

    The line you provided works exactly as desired and in addition I really
    appreciate you taking your time to explain the code. Stumbling around in the
    dark I managed to get pretty close, but failed to escape the | char.

    Thanks again!

    Happy Holidays,

    Patrick
     
    GRLCOPM, Dec 28, 2004
    #5
    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. Don Bruder
    Replies:
    11
    Views:
    609
    Kevin Goodsell
    Sep 21, 2003
  2. =?Utf-8?B?anJldHQ=?=

    ASP.NET rookie needs help finding postback data

    =?Utf-8?B?anJldHQ=?=, Sep 20, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    461
    =?Utf-8?B?anJldHQ=?=
    Sep 22, 2006
  3. jrett
    Replies:
    2
    Views:
    102
    Bob Barrows [MVP]
    Sep 20, 2006
  4. Chris L.

    Rookie Programming the Perl DBI..

    Chris L., Jan 28, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    104
    Xicheng
    Jan 30, 2006
  5. swangdb

    Rookie Perl Question

    swangdb, Jun 30, 2006, in forum: Perl Misc
    Replies:
    8
    Views:
    120
    John Bokma
    Jul 1, 2006
Loading...

Share This Page