Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple way to Reverse an Array

1 view
Skip to first unread message

Bill H

unread,
Feb 3, 2006, 11:19:51 AM2/3/06
to
If I use the following to load a file into an array, is there a simple
way of reversing the arrays contents?

open(FILE,"sometextfile.txt");
@THETEXTFILE = <FILE>;
close(FILE);

So $THETEXTFILE[0] holds line 1, [1] holds line 2 ect. other than doing
something like this is there a way to reverse the values?

for($i = @THETEXTFILE -1;$i >=0;$i++)
{
$THENEWFILE[@THENEWFILE] = $THETEXTFILE[$i];
}

I am just typing this in, not pasting actual code.

Bill H www.ts1000.us

Jürgen Exner

unread,
Feb 3, 2006, 11:23:22 AM2/3/06
to
Bill H wrote:
> If I use the following to load a file into an array, is there a simple
> way of reversing the arrays contents?

Has been a long time but finally we got a new SAQ (Self Answering Question).

Did you check "perldoc -f reverse"?

jue


Paul Lalli

unread,
Feb 3, 2006, 11:25:10 AM2/3/06
to

You have asked a SAQ: Self-Answering Question

Please do a *minimal* amount of searching before asking thousands of
people to read the documentation to you.

perldoc -f reverse
http://perldoc.perl.org/functions/reverse.html

Paul Lalli

Uri Guttman

unread,
Feb 3, 2006, 11:30:26 AM2/3/06
to pe...@ginini.com
>>>>> "BH" == Bill H <bi...@ts1000.us> writes:

BH> If I use the following to load a file into an array, is there a simple
BH> way of reversing the arrays contents?

SAQ!!

it deserves to be on this page (author is cc'ed)

http://www.ginini.com/perlsaq.html

try looking up the very word you used to describe the function you want
to perform. search perldoc perlfunc for it.

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

Bill H

unread,
Feb 3, 2006, 12:00:47 PM2/3/06
to

Thanks for pointing this out to me, knew there was an easy way to do it.

A. Sinan Unur

unread,
Feb 3, 2006, 1:54:17 PM2/3/06
to
"Bill H" <bi...@ts1000.us> wrote in
news:1138983591....@o13g2000cwo.googlegroups.com:

> If I use the following to load a file into an array, is there a simple
> way of reversing the arrays contents?
>
> open(FILE,"sometextfile.txt");
> @THETEXTFILE = <FILE>;
> close(FILE);
>
> So $THETEXTFILE[0] holds line 1, [1] holds line 2 ect. other than
> doing something like this is there a way to reverse the values?

Your basic question has been answered, but is there any chance you are
actually trying to read the file backwards?

See http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm

Sinan

--
A. Sinan Unur <1u...@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

use...@davidfilmer.com

unread,
Feb 3, 2006, 2:30:43 PM2/3/06
to
Jürgen Exner wrote:
> Has been a long time but finally we got a new SAQ (Self Answering Question).

So has anyone actually let Peter know?

Uri Guttman

unread,
Feb 3, 2006, 2:40:48 PM2/3/06
to
>>>>> "u" == usenet <use...@DavidFilmer.com> writes:

u> Jürgen Exner wrote:

>> Has been a long time but finally we got a new SAQ (Self Answering
>> Question).

u> So has anyone actually let Peter know?

i cc'ed him on my previous post in this thread.

he tends to be slow to respond or update that page. i had to google to
find it and it wasn't even found by google (at least on the front page!)
but several others had links to it. it is always an amusing read!

Bill H

unread,
Feb 3, 2006, 2:40:50 PM2/3/06
to

A. Sinan Unur wrote:
> "Bill H" <bi...@ts1000.us> wrote in
> news:1138983591....@o13g2000cwo.googlegroups.com:
>
> > If I use the following to load a file into an array, is there a simple
> > way of reversing the arrays contents?
> >
> > open(FILE,"sometextfile.txt");
> > @THETEXTFILE = <FILE>;
> > close(FILE);
> >
> > So $THETEXTFILE[0] holds line 1, [1] holds line 2 ect. other than
> > doing something like this is there a way to reverse the values?
>
> Your basic question has been answered, but is there any chance you are
> actually trying to read the file backwards?
>
> See http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm

Actually I am trying to read it backwards so that I can display the
most recent entry first (it is a simple log file). I will look at this
link you sent in more detail.

Bill H

Peter Sundstrom

unread,
Feb 3, 2006, 2:55:51 PM2/3/06
to

"Bill H" <bi...@ts1000.us> wrote in message
news:1138983591....@o13g2000cwo.googlegroups.com...

> If I use the following to load a file into an array, is there a simple
> way of reversing the arrays contents?
>
> open(FILE,"sometextfile.txt");
> @THETEXTFILE = <FILE>;
> close(FILE);

Congratulations, you've just earned yourself an entry in the Perl SAQ.

http://www.ginini.com/perlsaq.html


foofo...@hotmail.com

unread,
Feb 3, 2006, 2:56:37 PM2/3/06
to

Uri Guttman wrote:
> >>>>> "u" == usenet <use...@DavidFilmer.com> writes:
>
> u> Jürgen Exner wrote:
>
> >> Has been a long time but finally we got a new SAQ (Self Answering
> >> Question).
>
> u> So has anyone actually let Peter know?
>
> i cc'ed him on my previous post in this thread.
>
> he tends to be slow to respond or update that page. i had to google to
> find it and it wasn't even found by google (at least on the front page!)
> but several others had links to it. it is always an amusing read!

So are your posts, Urine Buttman. Learn how to use the Shift key,
fucktard!

Peter Sundstrom

unread,
Feb 3, 2006, 2:57:36 PM2/3/06
to

"Uri Guttman" <u...@stemsystems.com> wrote in message
news:x78xsss...@mail.sysarch.com...

> >>>>> "u" == usenet <use...@DavidFilmer.com> writes:
>
> u> Jürgen Exner wrote:
>
> >> Has been a long time but finally we got a new SAQ (Self Answering
> >> Question).
>
> u> So has anyone actually let Peter know?
>
> i cc'ed him on my previous post in this thread.
>
> he tends to be slow to respond or update that page. i had to google to
> find it and it wasn't even found by google (at least on the front page!)
> but several others had links to it. it is always an amusing read!

I'm usually pretty quick actually. Keep in mind that my timezone is GMT-12
and the time the OP's question reached me was 5:20am and I updated the
website at 8:55am (localtime), I'd say that's pretty good :-)


Paul Lalli

unread,
Feb 3, 2006, 3:10:15 PM2/3/06
to
Peter Sundstrom wrote:
> http://www.ginini.com/perlsaq.html

That page is suffering from a lack of CGI::escapeHTML() (or the
equivalent for whatever you're using to maintain the site). :-)

Paul Lalli

A. Sinan Unur

unread,
Feb 3, 2006, 3:11:26 PM2/3/06
to
foofo...@hotmail.com wrote in
news:1138996597.1...@g47g2000cwa.googlegroups.com:

>
> So are your posts, Urine Buttman. Learn how to use the Shift key,
> fucktard!
>

That's pure genius. Were you able to come up with that all on
your own?

I would like to bring to your attention:

http://www.mcnc.org/index.cfm?fuseaction=page&filename=ncren_acceptable_use.html

c. Neither Subscriber nor Subscriber’s users shall stalk others, post,
transmit, or originate any unlawful, threatening, abusive, fraudulent,
hateful, defamatory, obscene, or pornographic communication,

Abuse report sent.

DJ Stunks

unread,
Feb 3, 2006, 3:31:31 PM2/3/06
to

foofo...@hotmail.com wrote:
> <bizarre insane rant snipped>

someone's off their meds...

Peter Sundstrom

unread,
Feb 3, 2006, 3:39:21 PM2/3/06
to

"Paul Lalli" <mri...@gmail.com> wrote in message
news:1138997415....@g47g2000cwa.googlegroups.com...

Please explain? Do you mean non-escaping of characters such as < and >? I
was under the impression that if they are in a <pre> tag block you don't
need to escape them. Of course, this is getting a bit of topic for clpm.

The Perl SAQ page is maintained manually with vi, the editor of champions
;-)


Paul Lalli

unread,
Feb 3, 2006, 3:58:03 PM2/3/06
to
Peter Sundstrom wrote:
> "Paul Lalli" <mri...@gmail.com> wrote in message
> news:1138997415....@g47g2000cwa.googlegroups.com...
> > Peter Sundstrom wrote:
> > > http://www.ginini.com/perlsaq.html
> >
> > That page is suffering from a lack of CGI::escapeHTML() (or the
> > equivalent for whatever you're using to maintain the site). :-)
>
> Please explain? Do you mean non-escaping of characters such as < and >? I
> was under the impression that if they are in a <pre> tag block you don't
> need to escape them. Of course, this is getting a bit of topic for clpm.

Yes, that's what I was talking about. And I can find no mention of
<pre> removing the requirement for escaping entities at
http://www.w3.org/TR/REC-html40/struct/text.html#h-9.3.4

Indeed, the page viewed both in IE and Firefox (the only browsers I
have available right now) both show the < > as rendering (non-existant)
tags, rather than the characters themselves...

Paul Lalli

Uri Guttman

unread,
Feb 3, 2006, 5:26:23 PM2/3/06
to
>>>>> "PS" == Peter Sundstrom <pe...@ginini.com> writes:

PS> "Uri Guttman" <u...@stemsystems.com> wrote in message
PS> news:x78xsss...@mail.sysarch.com...


>> >>>>> "u" == usenet <use...@DavidFilmer.com> writes:
>>
u> Jürgen Exner wrote:
>>
>> >> Has been a long time but finally we got a new SAQ (Self Answering
>> >> Question).
>>
u> So has anyone actually let Peter know?
>>
>> i cc'ed him on my previous post in this thread.
>>
>> he tends to be slow to respond or update that page. i had to google to
>> find it and it wasn't even found by google (at least on the front page!)
>> but several others had links to it. it is always an amusing read!

PS> I'm usually pretty quick actually. Keep in mind that my timezone
PS> is GMT-12 and the time the OP's question reached me was 5:20am and
PS> I updated the website at 8:55am (localtime), I'd say that's pretty
PS> good :-)

sorry for the slight insult! :) and i see the updated page now. just
curious, but could you put in the date of each entry? then we could
track when SAQ's get created.

and IIRC when i last emailed you an SAQ i noticed your page hasn't been
updated in a while. maybe i was thinking that and it wasn't your
response time. that just means we don't get enough SAQ's here (or
elsewhere)!

and at least i didn't pull out my 3rd grade insult dictionary and abuse
you with that! :)

Uri Guttman

unread,
Feb 3, 2006, 5:30:28 PM2/3/06
to
>>>>> "PL" == Paul Lalli <mri...@gmail.com> writes:

PL> Peter Sundstrom wrote:
>> >
>> > That page is suffering from a lack of CGI::escapeHTML() (or the
>> > equivalent for whatever you're using to maintain the site). :-)
>>
>> Please explain? Do you mean non-escaping of characters such as < and >? I
>> was under the impression that if they are in a <pre> tag block you don't
>> need to escape them. Of course, this is getting a bit of topic for clpm.

PL> Indeed, the page viewed both in IE and Firefox (the only browsers I
PL> have available right now) both show the < > as rendering (non-existant)
PL> tags, rather than the characters themselves...

i see <> just fine in the quoted areas.

$hash->{'fred"}
ls > /tmp/workfile
@arr = `cat /etc/passwd 2>&1 `;
123<#>38923<#>hewfwiehi

this is firefox 1.5 on linux.

i can try exploder but i don't have enough pain killers at the moment to
do so.

Peter Sundstrom

unread,
Feb 3, 2006, 7:14:25 PM2/3/06
to

"Paul Lalli" <mri...@gmail.com> wrote in message
news:1139000283.3...@z14g2000cwz.googlegroups.com...

You are quite correct. It just so happens that all the previous entries
(apart from the two newest) didn't have any filehandles in the code, hence
the reason why I never picked it up until now.

I've now corrected the escaping.


Peter Sundstrom

unread,
Feb 3, 2006, 7:16:26 PM2/3/06
to

"Uri Guttman" <u...@stemsystems.com> wrote in message
news:x7psm4q...@mail.sysarch.com...

> >>>>> "PS" == Peter Sundstrom <pe...@ginini.com> writes:
> PS> I'm usually pretty quick actually. Keep in mind that my timezone
> PS> is GMT-12 and the time the OP's question reached me was 5:20am and
> PS> I updated the website at 8:55am (localtime), I'd say that's pretty
> PS> good :-)
>
> sorry for the slight insult! :) and i see the updated page now. just
> curious, but could you put in the date of each entry? then we could
> track when SAQ's get created.

I'll do that from now on.


> and IIRC when i last emailed you an SAQ i noticed your page hasn't been
> updated in a while. maybe i was thinking that and it wasn't your
> response time. that just means we don't get enough SAQ's here (or
> elsewhere)!

Perl SAQ's tend to come in a group and then go really quiet for a long time.
Expect a couple more in the next few weeks :-)

use...@davidfilmer.com

unread,
Feb 3, 2006, 7:30:59 PM2/3/06
to
Peter Sundstrom wrote:
> Please explain? Do you mean non-escaping of characters such as < and >? I
> was under the impression that if they are in a <pre> tag block you don't
> need to escape them.

FWIW, the page displays properly on my systems (Firefox on SuSE and
Windows). I dusted off IE on XP and it looks OK there also.

> The Perl SAQ page is maintained manually with vi, the editor of champions

Hee, hee - even Bill Joy has said he cannot understand why anyone still
uses vi :^}

And he wrote it.

--
http://DavidFilmer.com

use...@davidfilmer.com

unread,
Feb 3, 2006, 7:38:51 PM2/3/06
to
Bill H wrote:
> Actually I am trying to read it backwards so that I can display the
> most recent entry first (it is a simple log file).

Are you saying you don't understand that you can read it forwards into
an array and just use the reverse() function to process (ie, display)
it backwards?

Of course, if you REALLY want to read the file backwards, you can use
the File::ReadBackwards module (I'm not making this up - see
http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm).

Or, the IO::All module acts as a proxy for File::ReadBackwards, and
IO::All makes your life easy, so it would be as simple as:

#!/usr/bin/perl
use strict; use warnings;
use IO::All;

print io('file.txt') -> backwards -> slurp; # EASY!

__END__

Of course, filehandles, opening & closing, and error handling/reporting
are all provided by the IO::All module.

--
http://DavidFilmer.com

use...@davidfilmer.com

unread,
Feb 3, 2006, 8:16:16 PM2/3/06
to
A. Sinan Unur wrote:
> Abuse report sent.

I couldn't find an abuse-report contact address on MCNC's website. Did
you just assume that abuse@... would work (as it often does), or did
you find actual abuse contact information?

Keith Thompson

unread,
Feb 3, 2006, 9:00:26 PM2/3/06
to
"Paul Lalli" <mri...@gmail.com> writes:
> Peter Sundstrom wrote:
>> "Paul Lalli" <mri...@gmail.com> wrote in message
>> news:1138997415....@g47g2000cwa.googlegroups.com...
>> > Peter Sundstrom wrote:
>> > > http://www.ginini.com/perlsaq.html
>> >
>> > That page is suffering from a lack of CGI::escapeHTML() (or the
>> > equivalent for whatever you're using to maintain the site). :-)
>>
>> Please explain? Do you mean non-escaping of characters such as < and >? I
>> was under the impression that if they are in a <pre> tag block you don't
>> need to escape them. Of course, this is getting a bit of topic for clpm.
>
> Yes, that's what I was talking about. And I can find no mention of
> <pre> removing the requirement for escaping entities at
> http://www.w3.org/TR/REC-html40/struct/text.html#h-9.3.4

If '<' and '>' had no special meaning after <pre>, how would the
closing </pre> tag be recognized?

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

A. Sinan Unur

unread,
Feb 4, 2006, 12:27:38 PM2/4/06
to
use...@DavidFilmer.com wrote in news:1139015776.380018.325540
@g43g2000cwa.googlegroups.com:

Injection-Info: g47g2000cwa.googlegroups.com; posting-host=152.31.32.65;

C:\> whois 152.31.32.65

OrgName: North Carolina Research and Education Network

I sent to report both to GG and ncret.net. Let each sort out what they can
do.

A. Sinan Unur

unread,
Feb 4, 2006, 12:30:31 PM2/4/06
to
use...@DavidFilmer.com wrote in news:1139013531.007769.116620
@g44g2000cwa.googlegroups.com:

> Bill H wrote:
>> Actually I am trying to read it backwards so that I can display the
>> most recent entry first (it is a simple log file).
>
> Are you saying you don't understand that you can read it forwards into
> an array and just use the reverse() function to process (ie, display)
> it backwards?
>
> Of course, if you REALLY want to read the file backwards, you can use
> the File::ReadBackwards module (I'm not making this up - see
> http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm).

If the log files are large, reading it in small chunks starting from end,
and proceeding towards the top will be more practical.

Uri Guttman

unread,
Feb 4, 2006, 1:58:00 PM2/4/06
to
>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:

ASU> use...@DavidFilmer.com wrote in news:1139013531.007769.116620
ASU> @g44g2000cwa.googlegroups.com:

>> Of course, if you REALLY want to read the file backwards, you can use
>> the File::ReadBackwards module (I'm not making this up - see
>> http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm).

ASU> If the log files are large, reading it in small chunks starting
ASU> from end, and proceeding towards the top will be more practical.

and how do you think File::ReadBackwards works? by reading the file
forward and calling reverse on that list? please check out the module's
docs before you say what would be more practical. :)

Matt Garrish

unread,
Feb 4, 2006, 2:07:04 PM2/4/06
to

"Uri Guttman" <u...@stemsystems.com> wrote in message
news:x7y80rn...@mail.sysarch.com...

>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:
>
> ASU> use...@DavidFilmer.com wrote in news:1139013531.007769.116620
> ASU> @g44g2000cwa.googlegroups.com:
>
> >> Of course, if you REALLY want to read the file backwards, you can use
> >> the File::ReadBackwards module (I'm not making this up - see
> >> http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm).
>
> ASU> If the log files are large, reading it in small chunks starting
> ASU> from end, and proceeding towards the top will be more practical.
>
> and how do you think File::ReadBackwards works? by reading the file
> forward and calling reverse on that list? please check out the module's
> docs before you say what would be more practical. :)
>

Just cause you slapped your name on it doesn't convince me you know how it
works... : )

Matt


A. Sinan Unur

unread,
Feb 4, 2006, 2:28:58 PM2/4/06
to
Uri Guttman <u...@stemsystems.com> wrote in
news:x7y80rn...@mail.sysarch.com:

>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:
>
> ASU> use...@DavidFilmer.com wrote in news:1139013531.007769.116620
> ASU> @g44g2000cwa.googlegroups.com:
>
> >> Of course, if you REALLY want to read the file backwards, you can
> >> use the File::ReadBackwards module (I'm not making this up - see
> >> http://search.cpan.org/~uri/File-ReadBackwards-
1.04/ReadBackwards.p
> >> m).
>
> ASU> If the log files are large, reading it in small chunks starting
> ASU> from end, and proceeding towards the top will be more
> practical.
>
> and how do you think File::ReadBackwards works? by reading the file
> forward and calling reverse on that list? please check out the
> module's docs before you say what would be more practical. :)

I think you missed part of my point, and jumped the gun a little here. I
know what File::ReadBackwards does ... Inded, I am the one who first
suggested it in this thread. See:

http://groups.google.com/group/comp.lang.perl.misc/msg/a811a14fbe6e7353

The capitalization in David Filmer's 'REALLY' implied to me that he was
not convinced that it was a good idea to read the log file backwards.
So, I tried to explain to him and others why using your module is a
better idea than

my @log = reverse <$log>;

Hope this clarifies things a little.

Uri Guttman

unread,
Feb 4, 2006, 2:37:47 PM2/4/06
to
>>>>> "MG" == Matt Garrish <matthew...@sympatico.ca> writes:

MG> "Uri Guttman" <u...@stemsystems.com> wrote in message
MG> news:x7y80rn...@mail.sysarch.com...


>>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:
>>
ASU> use...@DavidFilmer.com wrote in news:1139013531.007769.116620
ASU> @g44g2000cwa.googlegroups.com:
>>
>> >> Of course, if you REALLY want to read the file backwards, you can use
>> >> the File::ReadBackwards module (I'm not making this up - see
>> >> http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm).
>>
ASU> If the log files are large, reading it in small chunks starting
ASU> from end, and proceeding towards the top will be more practical.
>>
>> and how do you think File::ReadBackwards works? by reading the file
>> forward and calling reverse on that list? please check out the module's
>> docs before you say what would be more practical. :)
>>

MG> Just cause you slapped your name on it doesn't convince me you
MG> know how it works... : )

well, you figured me out! i copied the guts of it from some script i
found on matt's archive. are you that matt? your code is so e133t i had
to steal it! i learned so much about efficiency and quality perl coding
from it.

:-)

Uri Guttman

unread,
Feb 4, 2006, 2:39:39 PM2/4/06
to
>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:

ASU> Uri Guttman <u...@stemsystems.com> wrote in
ASU> news:x7y80rn...@mail.sysarch.com:

>>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:
>>
ASU> use...@DavidFilmer.com wrote in news:1139013531.007769.116620
ASU> @g44g2000cwa.googlegroups.com:
>>
>> >> Of course, if you REALLY want to read the file backwards, you can
>> >> use the File::ReadBackwards module (I'm not making this up - see
>> >> http://search.cpan.org/~uri/File-ReadBackwards-

ASU> 1.04/ReadBackwards.p


>> >> m).
>>
ASU> If the log files are large, reading it in small chunks starting
ASU> from end, and proceeding towards the top will be more
>> practical.
>>
>> and how do you think File::ReadBackwards works? by reading the file
>> forward and calling reverse on that list? please check out the
>> module's docs before you say what would be more practical. :)

ASU> I think you missed part of my point, and jumped the gun a little here. I
ASU> know what File::ReadBackwards does ... Inded, I am the one who first
ASU> suggested it in this thread. See:

ASU> http://groups.google.com/group/comp.lang.perl.misc/msg/a811a14fbe6e7353

ASU> The capitalization in David Filmer's 'REALLY' implied to me that he was
ASU> not convinced that it was a good idea to read the log file backwards.
ASU> So, I tried to explain to him and others why using your module is a
ASU> better idea than

ASU> Hope this clarifies things a little.

makes a little more sense now. but then i tend to read posts backwards
which is why i wrote that module. must be all the top posting i see all
over! :)

A. Sinan Unur

unread,
Feb 4, 2006, 2:47:49 PM2/4/06
to
Uri Guttman <u...@stemsystems.com> wrote in
news:x7ek2io...@mail.sysarch.com:

>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:

...

> ASU> Hope this clarifies things a little.
>
> makes a little more sense now.

By the way, a belated thanks for the module. It saved me time and effort
quite a few times.

> but then i tend to read posts backwards which is why i wrote that
> module. must be all the top posting i see all over! :)

;-)

Uri Guttman

unread,
Feb 4, 2006, 3:15:04 PM2/4/06
to
>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:

ASU> Uri Guttman <u...@stemsystems.com> wrote in
ASU> news:x7ek2io...@mail.sysarch.com:

>>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:

ASU> ...

ASU> Hope this clarifies things a little.
>>
>> makes a little more sense now.

ASU> By the way, a belated thanks for the module. It saved me time and
ASU> effort quite a few times.

and the ironic thing is that i have never actually used this module
myself. i just don't ever seem to need to process logs and other large
files backwards. i wrote it to quiet the constant request for an easy
and fast way to do this. the perl cookbook 1st ed. has an awful solution
of scanning the file forward by lines and storing each line's seek point
in an array and then using that to read backwards by seeking to and
reading a line.

it was also a good exercise in writing a module that was focused on
those two requirements. i think it makes for an interesting piece of
well written code that would be worth reading by anyone into perl. of
course your comments on it are welcome and will be redirected to
/dev/null. :) and it seems to have become the community standard way to
do do this.

Dr.Ruud

unread,
Feb 5, 2006, 6:26:42 AM2/5/06
to
A. Sinan Unur schreef:

> A. Sinan Unur <1u...@llenroc.ude.invalid>
> (reverse each component and remove .invalid for email address)

echo 'c...@fed.ihg.invalid' \
| perl -ple '@_=/(\w+|.)/g;pop@_,pop@_;$_=reverse@_=reverse@_'

--
Affijn, Ruud

"Gewoon is een tijger."

Matt Garrish

unread,
Feb 5, 2006, 10:47:47 AM2/5/06
to

"Uri Guttman" <u...@stemsystems.com> wrote in message
news:x7irruo...@mail.sysarch.com...

>>>>>> "MG" == Matt Garrish <matthew...@sympatico.ca> writes:
>
> MG> "Uri Guttman" <u...@stemsystems.com> wrote in message
> MG> news:x7y80rn...@mail.sysarch.com...
> >>>>>>> "ASU" == A Sinan Unur <1u...@llenroc.ude.invalid> writes:
> >>
> ASU> use...@DavidFilmer.com wrote in news:1139013531.007769.116620
> ASU> @g44g2000cwa.googlegroups.com:
> >>
> >> >> Of course, if you REALLY want to read the file backwards, you can
> use
> >> >> the File::ReadBackwards module (I'm not making this up - see
> >> >>
> http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm).
> >>
> ASU> If the log files are large, reading it in small chunks starting
> ASU> from end, and proceeding towards the top will be more practical.
> >>
> >> and how do you think File::ReadBackwards works? by reading the file
> >> forward and calling reverse on that list? please check out the
> module's
> >> docs before you say what would be more practical. :)
> >>
>
> MG> Just cause you slapped your name on it doesn't convince me you
> MG> know how it works... : )
>
> well, you figured me out! i copied the guts of it from some script i
> found on matt's archive. are you that matt? your code is so e133t i had
> to steal it! i learned so much about efficiency and quality perl coding
> from it.
>

Props to me and my archive, d00d! ; )

Matt


Dr.Ruud

unread,
Feb 6, 2006, 7:33:47 AM2/6/06
to
Dr.Ruud:
> A. Sinan Unur:

>> A. Sinan Unur <1u...@llenroc.ude.invalid>
>> (reverse each component and remove .invalid for email address)
>
> echo 'c...@fed.ihg.invalid' \
> | perl -ple '@_=/(\w+|.)/g;pop@_,pop@_;$_=reverse@_=reverse@_'

| perl -ple 'split/(\W)/;pop@_;pop@_;$_=reverse@_=reverse@_'

Anno Siegel

unread,
Feb 6, 2006, 9:23:44 AM2/6/06
to
Dr.Ruud <rvtol...@isolution.nl> wrote in comp.lang.perl.misc:

> Dr.Ruud:
> > A. Sinan Unur:
>
> >> A. Sinan Unur <1u...@llenroc.ude.invalid>
> >> (reverse each component and remove .invalid for email address)
> >
> > echo 'c...@fed.ihg.invalid' \
> > | perl -ple '@_=/(\w+|.)/g;pop@_,pop@_;$_=reverse@_=reverse@_'
>
> | perl -ple 'split/(\W)/;pop@_;pop@_;$_=reverse@_=reverse@_'

| perl -ple 's/\.[^.]+$//;s/(\w+)/reverse$1/eg'

Much more pedestrian, but shorter is shorter.

Anno, who used to say he doesn't do golf.
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

googo...@hotmail.com

unread,
Feb 6, 2006, 1:14:34 PM2/6/06
to

HAHAHA A.Sinine Usurer got mad.

Check out what students say about him at ratemyprofessors.com:

Gets confused quite easily with information. Review for Final was a 3
hour session which he emphasized a whole area to memorize only to not
include it in the final at all.

Most retarded teacher at Cornell; he couldn't even solve 2x=12 to
derive the eq. pt.

Unur is useless at life. You do not learn a single thing in this class.
It's a joke.

as...@cornell.edu
as...@cornell.edu
as...@cornell.edu

Dr.Ruud

unread,
Feb 6, 2006, 2:19:16 PM2/6/06
to
Anno Siegel:
> Dr.Ruud:
>> Dr.Ruud:
>>> A. Sinan Unur:

>>>> A. Sinan Unur <1u...@llenroc.ude.invalid>
>>>> (reverse each component and remove .invalid for email address)
>>>
>>> echo 'c...@fed.ihg.invalid' \
>>> | perl -ple '@_=/(\w+|.)/g;pop@_,pop@_;$_=reverse@_=reverse@_'
>>
>> | perl -ple 'split/(\W)/;pop@_;pop@_;$_=reverse@_=reverse@_'
>
> | perl -ple 's/\.[^.]+$//;s/(\w+)/reverse$1/eg'
>
> Much more pedestrian, but shorter is shorter.

Cool, but out of topic. <g>

It can be shortened to(o):

| perl -ple 's/.\w+$//;s/(\w+)/reverse$1/eg'

A. Sinan Unur

unread,
Feb 6, 2006, 4:45:38 PM2/6/06
to
googo...@hotmail.com wrote in
news:1139249674.6...@g47g2000cwa.googlegroups.com:

[ I apologize for falling for this troll but I am posting this just in
case any of my students stumbles upon this posting. I will, under no
circumstances, post on this thread again. ]

> A. Sinan Unur wrote:
...

> Check out what students say about him at ratemyprofessors.com:

The URL is:

http://www.ratemyprofessors.com/ShowRatings.jsp?tid=479462

Honestly, over the last 15 years during which I have been teaching in
one capacity or another, I have received both better and worse
evaluations.

I try to give my students the service they deserve for the money they
are spending on their education.

Every time I receive feedback pointing out my shortcomings, I do my best
to improve myself. It is even better if the critcism is accompanied with
suggestions on how things can be improved.

Anno Siegel

unread,
Feb 6, 2006, 5:06:59 PM2/6/06
to
Dr.Ruud <rvtol...@isolution.nl> wrote in comp.lang.perl.misc:

Nice. Dot matches dot, even unescaped.

Anno

Dr.Ruud

unread,
Feb 6, 2006, 5:35:20 PM2/6/06
to
Anno Siegel:
> Dr.Ruud:

>> Anno Siegel:
>>> Dr.Ruud:
>>>> Dr.Ruud:
>>>>> A. Sinan Unur:

>>>>>> A. Sinan Unur <1u...@llenroc.ude.invalid>
>>>>>> (reverse each component and remove .invalid for email address)
>>>>>
>>>>> echo 'c...@fed.ihg.invalid' \
>>>>> | perl -ple '@_=/(\w+|.)/g;pop@_,pop@_;$_=reverse@_=reverse@_'
>>>>
>>>> | perl -ple 'split/(\W)/;pop@_;pop@_;$_=reverse@_=reverse@_'
>>>
>>> | perl -ple 's/\.[^.]+$//;s/(\w+)/reverse$1/eg'
>>

>> | perl -ple 's/.\w+$//;s/(\w+)/reverse$1/eg'
>
> Nice. Dot matches dot, even unescaped.

I had such a twist in my first version, and it was indeed nice to repeat
it.

Matt Garrish

unread,
Feb 6, 2006, 6:31:19 PM2/6/06
to

"A. Sinan Unur" <1u...@llenroc.ude.invalid> wrote in message
news:Xns9762AA95BD0C...@127.0.0.1...

> googo...@hotmail.com wrote in
> news:1139249674.6...@g47g2000cwa.googlegroups.com:
>
> [ I apologize for falling for this troll but I am posting this just in
> case any of my students stumbles upon this posting. I will, under no
> circumstances, post on this thread again. ]
>
>> A. Sinan Unur wrote:
> ...
>
>> Check out what students say about him at ratemyprofessors.com:
>
> The URL is:
>
> http://www.ratemyprofessors.com/ShowRatings.jsp?tid=479462
>
> Honestly, over the last 15 years during which I have been teaching in
> one capacity or another, I have received both better and worse
> evaluations.
>

And really, aren't those sites mostly geared toward people with an axe to
grind? At least where I went to university, full polling of all students was
done each semester for each class, and the results were available in the
department office for the last couple of years if you wanted to look. A far
more accurate picture I would think, as the biggest complainers were
probably skipping class that day anyway, hence their inevitable failure...
: )

Matt


A. Sinan Unur

unread,
Feb 6, 2006, 7:00:27 PM2/6/06
to
"Matt Garrish" <matthew...@sympatico.ca> wrote in
news:9%QFf.2081$J%6.11...@news20.bellglobal.com:

>
> "A. Sinan Unur" <1u...@llenroc.ude.invalid> wrote in message
> news:Xns9762AA95BD0C...@127.0.0.1...
>> googo...@hotmail.com wrote in
>> news:1139249674.6...@g47g2000cwa.googlegroups.com:
>>
>> [ I apologize for falling for this troll but I am posting this just
>> in case any of my students stumbles upon this posting. I will, under
>> no circumstances, post on this thread again. ]
>>
>>> A. Sinan Unur wrote:
>> ...
>>
>>> Check out what students say about him at ratemyprofessors.com:
>>
>> The URL is:
>>
>> http://www.ratemyprofessors.com/ShowRatings.jsp?tid=479462

...

> And really, aren't those sites mostly geared toward people with an axe
> to grind? At least where I went to university, full polling of all
> students was done each semester for each class, and the results were
> available in the department office for the last couple of years if you
> wanted to look. A far more accurate picture I would think, as the
> biggest complainers were probably skipping class that day anyway,
> hence their inevitable failure...
>: )

Breaking my promise immediately ;-)

My department has switched to anonymous online evaluations. These
evaluations are available for a period of about two weeks during the
finals period.

Once we turn in the grades, we receive printouts of everyone's input
(completely anonymized).

And we all get the occasional evaluation filled with profanities. In
fact, one of the evaluations I received last semester contained some
nasty language, but it was not representative.

I think there is a difference in what people say when they have to
actually put their thoughts on paper versus when they are just filling
in a form online.

Matt Garrish

unread,
Feb 6, 2006, 8:45:59 PM2/6/06
to

"A. Sinan Unur" <1u...@llenroc.ude.invalid> wrote in message
news:Xns9762C170997A...@127.0.0.1...

Hmm, oddly like usenet... ; )

I was actually afraid that a prof would identify my comments by my
handwriting, though (until I learned that the comments were typed up before
being passed on). I actually had one prof look at my final exam in a third
year course and then ask me if I had been in his first year class because he
remembered my handwriting (yes, he explicitly said handwriting!). The
electronic experience does seem to encourage what would otherwise be
considered anti-social behaviour on the part of some people, but maybe we
should leave this topic to the sociologists.

Matt


John W. Krahn

unread,
Feb 7, 2006, 2:07:37 AM2/7/06
to

| perl -ple 's/.\w+$//;s/\w+/reverse$&/eg'


John
--
use Perl;
program
fulfillment

Dr.Ruud

unread,
Feb 7, 2006, 11:44:03 AM2/7/06
to
John W. Krahn:
> Dr.Ruud:

>> Anno Siegel:
>>> Dr.Ruud:
>>>> Dr.Ruud:
>>>>> A. Sinan Unur:

>>>>>> A. Sinan Unur <1u...@llenroc.ude.invalid>
>>>>>> (reverse each component and remove .invalid for email address)
>>>>> echo 'c...@fed.ihg.invalid' \
>>>>> | perl -ple '@_=/(\w+|.)/g;pop@_,pop@_;$_=reverse@_=reverse@_'
>>>> | perl -ple 'split/(\W)/;pop@_;pop@_;$_=reverse@_=reverse@_'
>>> | perl -ple 's/\.[^.]+$//;s/(\w+)/reverse$1/eg'

>> | perl -ple 's/.\w+$//;s/(\w+)/reverse$1/eg'
>
> | perl -ple 's/.\w+$//;s/\w+/reverse$&/eg'

Thanks for exposing our prejudice.

Another array-reversing version:

| perl -aF'(\W)' -ple '$_=reverse reverse splice@F,0,-2'

0 new messages