if ($line == $count++)

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

  1. April

    April Guest

    looking at the following, if $line has values of 1, 2, 3, ... will the
    if test ever tests true when $line equals 1? It seems it won't as
    $count starts as 1 and then the test with $count++ (=2), but the
    execution suggests otherwise ...

    my $count = 1;
    while(<IN>)
    {
    if ($line == $count++)
    {
    $deleted = $_;
    next;
    }
    print OUT;
    }
    April, Oct 30, 2008
    #1
    1. Advertising

  2. April <> writes:

    > looking at the following, if $line has values of 1, 2, 3, ... will the
    > if test ever tests true when $line equals 1? It seems it won't as
    > $count starts as 1 and then the test with $count++ (=2), but the
    > execution suggests otherwise ...


    $i++ will return the value of $i before incrementing the value, so yes
    $line will become equal $count. Read the 'Auto-increment and
    Auto-decrement' section of 'perldoc perlop'.

    (But instead of counting lines, you could use the magic variable
    $. Read 'perldoc perlvar' for more information about this)

    //Makholm
    Peter Makholm, Oct 30, 2008
    #2
    1. Advertising

  3. April

    April Guest

    On Oct 30, 12:13 pm, Peter Makholm <> wrote:
    > April <> writes:
    > > looking at the following, if $line has values of 1, 2, 3, ... will the
    > > if test ever tests true when $line equals 1?  It seems it won't as
    > > $count starts as 1 and then the test with $count++ (=2), but the
    > > execution suggests otherwise ...

    >
    > $i++ will return the value of $i before incrementing the value, so yes
    > $line will become equal $count. Read the 'Auto-increment and
    > Auto-decrement' section of 'perldoc perlop'.
    >
    > (But instead of counting lines, you could use the magic variable
    > $. Read 'perldoc perlvar' for more information about this)
    >
    > //Makholm


    Thanks Peter for your quick answer!
    April, Oct 30, 2008
    #3
  4. April

    Tim Greer Guest

    April wrote:

    > looking at the following, if $line has values of 1, 2, 3, ... will the
    > if test ever tests true when $line equals 1? It seems it won't as
    > $count starts as 1 and then the test with $count++ (=2), but the
    > execution suggests otherwise ...
    >
    > my $count = 1;
    > while(<IN>)
    > {
    > if ($line == $count++)
    > {
    > $deleted = $_;
    > next;
    > }
    > print OUT;
    > }


    See the difference (for example) between $count++ and ++$count.
    --
    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 30, 2008
    #4
  5. April

    April Guest

    On Oct 30, 4:27 pm, Tim Greer <> wrote:
    > April wrote:
    > > looking at the following, if $line has values of 1, 2, 3, ... will the
    > > if test ever tests true when $line equals 1?  It seems it won't as
    > > $count starts as 1 and then the test with $count++ (=2), but the
    > > execution suggests otherwise ...

    >
    > >     my $count = 1;
    > >     while(<IN>)
    > >     {
    > >         if ($line == $count++)
    > >         {
    > >             $deleted = $_;
    > >             next;
    > >         }
    > >         print OUT;
    > >     }

    >
    > See the difference (for example) between $count++ and ++$count.
    > --
    > 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!- Hide quoted text -
    >
    > - Show quoted text -


    thanks Tim, haven't tested but guess ++$count would increment first?
    April, Nov 1, 2008
    #5
  6. April

    Tim Greer Guest

    April wrote:

    > On Oct 30, 4:27 pm, Tim Greer <> wrote:
    >> April wrote:
    >> > looking at the following, if $line has values of 1, 2, 3, ... will
    >> > the if test ever tests true when $line equals 1?  It seems it won't
    >> > as $count starts as 1 and then the test with $count++ (=2), but the
    >> > execution suggests otherwise ...

    >>
    >> > my $count = 1;
    >> > while(<IN>)
    >> > {
    >> > if ($line == $count++)
    >> > {
    >> > $deleted = $_;
    >> > next;
    >> > }
    >> > print OUT;
    >> > }

    >>
    >> See the difference (for example) between $count++ and ++$count.

    <please don't quote signatures>
    >>
    >> - Show quoted text -

    >
    > thanks Tim, haven't tested but guess ++$count would increment first?


    perldoc perlop:

    Auto-increment and Auto-decrement

    "++" and "--" work as in C. That is, if placed before a
    variable, they increment or decrement the variable by one before
    returning the value, and if placed after, increment or decrement after
    returning the value.

    $i = 0; $j = 0;
    print $i++; # prints 0
    print ++$j; # prints 1

    Now, if this will work for you, your purposes and your code, and how you
    want, is something I can't say, but that is the general idea. As
    another poster stated, using $. for line counting is probably a better
    idea, but it really depends on what you're doing.
    --
    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, Nov 1, 2008
    #6
  7. April

    April Guest

    On Nov 1, 2:12 pm, Tim Greer <> wrote:
    >
    > >> See the difference (for example) between $count++ and ++$count.

    >
    > <please don't quote signatures>
    >


    thanks Tim, I'll pay attention to this .. you know if you use Google
    Groups, then all the quotes are hidden automaticaly and you get a nice
    and clean interface. If you get a chance give it a try and you may
    like it. If you want to check the quotes, you can, and also all the
    posts for the same topic are in the same spot. I thought people are
    using this kind of web tools nowadays and did not pay much attention,
    besides I'm not familiar with the good old tradition either.

    >
    > > thanks Tim, haven't tested but guess ++$count would increment first?

    >
    > perldoc perlop:
    >
    >        Auto-increment and Auto-decrement
    >
    >        "++" and "--" work as in C.  That is, if placed before a
    > variable, they increment or decrement the variable by one before
    > returning the value, and if placed after, increment or decrement after
    > returning the value.
    >
    >            $i = 0;  $j = 0;
    >            print $i++;  # prints 0
    >            print ++$j;  # prints 1
    >
    > Now, if this will work for you, your purposes and your code, and how you
    > want, is something I can't say, but that is the general idea.  As
    > another poster stated, using $. for line counting is probably a better
    > idea, but it really depends on what you're doing.


    really appreciate this piece of info, thanks again Tim.
    April, Nov 2, 2008
    #7
  8. April wrote:
    > On Nov 1, 2:12 pm, Tim Greer <> wrote:
    >>>> See the difference (for example) between $count++ and ++$count.

    >> <please don't quote signatures>
    >>

    >
    > thanks Tim, I'll pay attention to this .. you know if you use Google
    > Groups, then all the quotes are hidden automaticaly and you get a nice
    > and clean interface. If you get a chance give it a try and you may
    > like it.


    Many of us have tried it and really dislike it. There are a number of
    reasons for this.

    I find that not only does it have many deficiencies and annoyances, it
    has bugs. For example, the article numbers in the tree-view sometimes
    don't match those in the main pane. Clicking an article in the tree-view
    can take you to a different message in the main view.

    Have you tried a proper news reader - like Thunderbird or even Outlook
    Express?


    > If you want to check the quotes, you can, and also all the
    > posts for the same topic are in the same spot.


    They are in a real newsreader but in GG they are spread over several
    pages, you have to select "Next Page" a lot. In a real newsreader you
    don't have this issue.


    > I thought people are
    > using this kind of web tools nowadays and did not pay much attention,
    > besides I'm not familiar with the good old tradition either.


    Here's a few questions I have about Google Groups:

    How do you jump easily to the next unread item?

    How do you mark an obnoxious poster so their future messages are
    automatically ignored?

    How do you configure it to delete spam before you read it?

    How do you get it to automatically highlight posts from people you respect?

    How do you get it to switch quickly between thread-order (tree view) and
    date order or author order?

    How do you jump quickly to the referred to posting?


    Have you tried a real newsreader program?

    --
    RGB
    RedGrittyBrick, Nov 2, 2008
    #8
  9. April

    Tim Greer Guest

    April wrote:

    > On Nov 1, 2:12 pm, Tim Greer <> wrote:
    >>
    >> >> See the difference (for example) between $count++ and ++$count.

    >>
    >> <please don't quote signatures>
    >>

    >
    > thanks Tim, I'll pay attention to this .. you know if you use Google
    > Groups, then all the quotes are hidden automaticaly and you get a nice
    > and clean interface. If you get a chance give it a try and you may
    > like it. If you want to check the quotes, you can, and also all the
    > posts for the same topic are in the same spot. I thought people are
    > using this kind of web tools nowadays and did not pay much attention,
    > besides I'm not familiar with the good old tradition either.
    >


    There are a lot of issues with services such as google groups. I'm not
    interested in it at all (I won't get into the reasons why google groups
    is less desirable in every single way, as that's best left to another
    topic in another group). Anyway, you might check to see if there's a
    configuration option in some 'preferences' area to view signatures or
    not have it quote them, or something. It just makes followups appear
    confusing as to whom typed what sometimes.
    --
    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, Nov 2, 2008
    #9
  10. April

    April Guest

    On Nov 2, 12:25 pm, RedGrittyBrick <>
    wrote:

    >
    > Here's a few questions I have about Google Groups:
    >
    > How do you jump easily to the next unread item?
    >
    > How do you mark an obnoxious poster so their future messages are
    > automatically ignored?
    >
    > How do you configure it to delete spam before you read it?
    >
    > How do you get it to automatically highlight posts from people you respect?
    >
    > How do you get it to switch quickly between thread-order (tree view) and
    > date order or author order?
    >
    > How do you jump quickly to the referred to posting?
    >
    > Have you tried a real newsreader program?
    >
    > --
    > RGB


    I see your needs as a newsgroup regular, which is quite different from
    mine. I only come to a particular newsgroup when I get an issue, and
    Google Groups seems meet my needs for that purpose.

    Yours seem well-thought-out questions, may consider to send to Google
    so they can may enhancement in the future.

    I did configure OE for newsgroup at one time, however, later lost it
    when HW upgraded. Then I found Google Groups and did not go back or
    any real readers.
    April, Nov 2, 2008
    #10
  11. April

    April Guest

    On Nov 2, 3:05 pm, Tim Greer <> wrote:
    >
    > Anyway, you might check to see if there's a
    > configuration option in some 'preferences' area to view signatures or
    > not have it quote them, or something.  


    Just looked but could not find one ...
    April, Nov 2, 2008
    #11
  12. April

    Tim Greer Guest

    April wrote:

    > On Nov 2, 3:05 pm, Tim Greer <> wrote:
    >>
    >> Anyway, you might check to see if there's a
    >> configuration option in some 'preferences' area to view signatures or
    >> not have it quote them, or something.

    >
    > Just looked but could not find one ...


    No matter, you seem to have found a way to not quote them in your recent
    replies, so that should work fine. I don't think anyone minds what
    usenet service you use, and if you are able to reply without google
    groups forcing some sig quote on you, then you're good. :)
    --
    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, Nov 2, 2008
    #12
  13. April

    Guest

    On Thu, 30 Oct 2008 09:07:38 -0700 (PDT), April <> wrote:

    >looking at the following, if $line has values of 1, 2, 3, ... will the
    >if test ever tests true when $line equals 1? It seems it won't as
    >$count starts as 1 and then the test with $count++ (=2), but the
    >execution suggests otherwise ...
    >
    > my $count = 1;
    > while(<IN>)
    > {
    > if ($line == $count++)
    > {
    > $deleted = $_;
    > next;
    > }
    > print OUT;
    > }


    $line is not part of this code.
    Possibly the simplest solution is the right one.
    Even if you can copy code, perhaps you shouldn't paste it.

    sln
    , Nov 3, 2008
    #13
  14. <> wrote:
    > On Thu, 30 Oct 2008 09:07:38 -0700 (PDT), April <> wrote:
    >
    >>looking at the following, if $line has values of 1, 2, 3, ... will the
    >>if test ever tests true when $line equals 1? It seems it won't as
    >>$count starts as 1 and then the test with $count++ (=2), but the
    >>execution suggests otherwise ...
    >>
    >> my $count = 1;
    >> while(<IN>)
    >> {
    >> if ($line == $count++)

    ^^^^^
    ^^^^^
    >> {
    >> $deleted = $_;
    >> next;
    >> }
    >> print OUT;
    >> }

    >
    > $line is not part of this code.



    $line is most certainly part of that code.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Nov 3, 2008
    #14
  15. April

    David Combs Guest

    In article <geknpp$nbs$>,
    RedGrittyBrick <> wrote:
    >
    >April wrote:
    >> On Nov 1, 2:12 pm, Tim Greer <> wrote:
    >>>>> See the difference (for example) between $count++ and ++$count.
    >>> <please don't quote signatures>
    >>>

    >>
    >> thanks Tim, I'll pay attention to this .. you know if you use Google
    >> Groups, then all the quotes are hidden automaticaly and you get a nice
    >> and clean interface. If you get a chance give it a try and you may
    >> like it.

    >
    >Many of us have tried it and really dislike it. There are a number of
    >reasons for this.
    >
    >I find that not only does it have many deficiencies and annoyances, it
    >has bugs. For example, the article numbers in the tree-view sometimes
    >don't match those in the main pane. Clicking an article in the tree-view
    >can take you to a different message in the main view.
    >
    >Have you tried a proper news reader - like Thunderbird or even Outlook
    >Express?


    How about trn4?



    David
    David Combs, Dec 1, 2008
    #15
  16. April

    David Combs Guest

    In article <NJnPk.34387$>,
    Tim Greer <> wrote:
    >April wrote:
    >
    >> On Nov 1, 2:12 pm, Tim Greer <> wrote:
    >>>
    >>> >> See the difference (for example) between $count++ and ++$count.
    >>>
    >>> <please don't quote signatures>
    >>>

    >>
    >> thanks Tim, I'll pay attention to this .. you know if you use Google
    >> Groups, then all the quotes are hidden automaticaly and you get a nice
    >> and clean interface. If you get a chance give it a try and you may
    >> like it. If you want to check the quotes, you can, and also all the
    >> posts for the same topic are in the same spot. I thought people are
    >> using this kind of web tools nowadays and did not pay much attention,
    >> besides I'm not familiar with the good old tradition either.
    >>

    >
    >There are a lot of issues with services such as google groups. I'm not
    >interested in it at all (I won't get into the reasons why google groups
    >is less desirable in every single way, as that's best left to another
    >topic in another group). Anyway, you might check to see if there's a
    >configuration option in some 'preferences' area to view signatures or
    >not have it quote them, or something. It just makes followups appear
    >confusing as to whom typed what sometimes.
    >--
    >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!


    One good thing about google groups is that it has access
    to stuff from months and years ago -- posts long gone
    from whatever local or isp-maintained usenet cash you might have
    access to.


    David
    David Combs, Dec 1, 2008
    #16
  17. David Combs <> wrote:
    > In article <NJnPk.34387$>,
    > Tim Greer <> wrote:


    >>--
    >>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!



    It is still poor manners to quote .sigs. Please don't do that.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Dec 1, 2008
    #17
  18. (David Combs) wrote:
    >One good thing about google groups is that it has access
    >to stuff from months and years ago -- posts long gone
    >from whatever local or isp-maintained usenet cash you might have
    >access to.


    Well, kind of.
    The Usenet archive known as DejaNews used to be better before Google
    bought it and renamed it Google Groups.
    Now in Google I can't even get a threaded tree view any longer.

    jue
    Jürgen Exner, Dec 1, 2008
    #18
  19. April

    Tim Greer Guest

    David Combs wrote:

    > In article <NJnPk.34387$>,
    > Tim Greer <> wrote:
    >>April wrote:
    >>
    >>> On Nov 1, 2:12 pm, Tim Greer <> wrote:
    >>>>
    >>>> >> See the difference (for example) between $count++ and ++$count.
    >>>>
    >>>> <please don't quote signatures>
    >>>>
    >>>
    >>> thanks Tim, I'll pay attention to this .. you know if you use Google
    >>> Groups, then all the quotes are hidden automaticaly and you get a
    >>> nice
    >>> and clean interface. If you get a chance give it a try and you may
    >>> like it. If you want to check the quotes, you can, and also all the
    >>> posts for the same topic are in the same spot. I thought people are
    >>> using this kind of web tools nowadays and did not pay much
    >>> attention, besides I'm not familiar with the good old tradition
    >>> either.
    >>>

    >>
    >>There are a lot of issues with services such as google groups. I'm
    >>not interested in it at all (I won't get into the reasons why google
    >>groups is less desirable in every single way, as that's best left to
    >>another
    >>topic in another group). Anyway, you might check to see if there's a
    >>configuration option in some 'preferences' area to view signatures or
    >>not have it quote them, or something. It just makes followups appear
    >>confusing as to whom typed what sometimes.
    >>--


    <please don't quote signatures>

    >
    > One good thing about google groups is that it has access
    > to stuff from months and years ago -- posts long gone
    > from whatever local or isp-maintained usenet cash you might have
    > access to.
    >
    >
    > David


    That debate would more accurately be about news readers, rather than
    archiving usenet articles. Speaking of, my news reader is configured
    (by me) to not display already "read" usenet articles that are over
    30-60 days old, so I'm unsure why you've been replying to such old
    articles in this group today? It makes it difficult to follow (and I
    really dislike google groups, so I'm not going there to check the
    history of this thread :)

    --
    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, Dec 1, 2008
    #19
  20. April

    Tim Greer Guest

    Jürgen Exner wrote:

    > (David Combs) wrote:
    >>One good thing about google groups is that it has access
    >>to stuff from months and years ago -- posts long gone
    >>from whatever local or isp-maintained usenet cash you might have
    >>access to.

    >
    > Well, kind of.
    > The Usenet archive known as DejaNews used to be better before Google
    > bought it and renamed it Google Groups.
    > Now in Google I can't even get a threaded tree view any longer.
    >
    > jue


    Agreed, Dejanews was far better, and I've not used it much since google
    took over (if I ever do need to refer to an old article).
    --
    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, Dec 1, 2008
    #20
    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. Hugo
    Replies:
    10
    Views:
    1,299
    Matt Humphrey
    Oct 18, 2004
  2. kaushikshome
    Replies:
    4
    Views:
    759
    kaushikshome
    Sep 10, 2006
  3. scad
    Replies:
    23
    Views:
    1,157
    Alf P. Steinbach
    May 17, 2009
  4. efelnavarro09
    Replies:
    2
    Views:
    929
    efelnavarro09
    Jan 26, 2011
  5. Replies:
    3
    Views:
    141
    Frank Seitz
    May 9, 2009
Loading...

Share This Page