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
Has been a long time but finally we got a new SAQ (Self Answering Question).
Did you check "perldoc -f reverse"?
jue
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
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
Thanks for pointing this out to me, knew there was an easy way to do it.
> 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
So has anyone actually let Peter know?
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!
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
Congratulations, you've just earned yourself an entry in the Perl SAQ.
http://www.ginini.com/perlsaq.html
So are your posts, Urine Buttman. Learn how to use the Shift key,
fucktard!
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 :-)
That page is suffering from a lack of CGI::escapeHTML() (or the
equivalent for whatever you're using to maintain the site). :-)
Paul Lalli
>
> 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.
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
;-)
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
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! :)
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.
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.
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 :-)
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.
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.
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?
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.
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.
> 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.
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
>>>>>> "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.
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.
:-)
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! :)
>>>>>> "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! :)
;-)
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.
> 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."
Props to me and my archive, d00d! ; )
Matt
>> 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.
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.
>>>> 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'
[ 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.
Nice. Dot matches dot, even unescaped.
Anno
>>>>>> 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.
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" <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.
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
| perl -ple 's/.\w+$//;s/\w+/reverse$&/eg'
John
--
use Perl;
program
fulfillment
>>>>>> 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'