Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > if ($line == $count++)

Reply
Thread Tools

if ($line == $count++)

 
 
April
Guest
Posts: n/a
 
      10-30-2008
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;
}
 
Reply With Quote
 
 
 
 
Peter Makholm
Guest
Posts: n/a
 
      10-30-2008
April <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
April
Guest
Posts: n/a
 
      10-30-2008
On Oct 30, 12:13*pm, Peter Makholm <(E-Mail Removed)> wrote:
> April <(E-Mail Removed)> 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!
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      10-30-2008
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!
 
Reply With Quote
 
April
Guest
Posts: n/a
 
      11-01-2008
On Oct 30, 4:27*pm, Tim Greer <(E-Mail Removed)> 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?
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      11-01-2008
April wrote:

> On Oct 30, 4:27*pm, Tim Greer <(E-Mail Removed)> 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!
 
Reply With Quote
 
April
Guest
Posts: n/a
 
      11-02-2008
On Nov 1, 2:12*pm, Tim Greer <(E-Mail Removed)> 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.




 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      11-02-2008

April wrote:
> On Nov 1, 2:12 pm, Tim Greer <(E-Mail Removed)> 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
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      11-02-2008
April wrote:

> On Nov 1, 2:12*pm, Tim Greer <(E-Mail Removed)> 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!
 
Reply With Quote
 
April
Guest
Posts: n/a
 
      11-02-2008
On Nov 2, 12:25*pm, RedGrittyBrick <(E-Mail Removed)>
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.






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments