[31728] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2991 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 15 00:09:23 2010

Date: Mon, 14 Jun 2010 21:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 14 Jun 2010     Volume: 11 Number: 2991

Today's topics:
    Re: File Content reversal-Not working with foreach and  <uri@StemSystems.com>
    Re: File Content reversal-Not working with foreach and  <jwkrahn@example.com>
    Re: File Content reversal-Not working with foreach and  <uri@StemSystems.com>
    Re: File Content reversal-Not working with foreach and  <jwkrahn@example.com>
    Re: File Content reversal-Not working with foreach and  <uri@StemSystems.com>
    Re: File::Slurp/IO::String/wantarray interaction bug <no.email@please.post>
    Re: File::Slurp/IO::String/wantarray interaction bug <no.email@please.post>
    Re: graphics <tzz@lifelogs.com>
    Re: graphics <mvdwege@mail.com>
    Re: graphics <nospam-abuse@ilyaz.org>
    Re: How to grep using an array of patterns? <john@castleamber.com>
    Re: How to grep using an array of patterns? <tadmc@seesig.invalid>
    Re: How to grep using an array of patterns? <john@castleamber.com>
    Re: How to grep using an array of patterns? <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 14 Jun 2010 11:24:42 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: File Content reversal-Not working with foreach and pop from array
Message-Id: <87d3vtiqmd.fsf@quad.sysarch.com>

>>>>> "d" == divyajacob  <divyajacobpulickal@gmail.com> writes:

just to stick my $.02 in with all the other good answers cause this is
shorter and likely faster.

  d> open (FILE,$str);


use File::ReadBackwards ; 	# get it from cpan

tie( *HANDLE, 'File::ReadBackwards', $str ) ;
print <HANDLE> ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Mon, 14 Jun 2010 09:42:02 -0700
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: File Content reversal-Not working with foreach and pop from array
Message-Id: <vZsRn.35263$7d5.3990@newsfe17.iad>

divyajacob wrote:
> I was trying out a program
>   Accept a filename as command line argument. Display the
> contents of that file in the opposite order that they appear in the
> file.
>
> file content is :-
>
> Three Rings for the Elven-kings under the sky,
> Seven for the Dwarf-lords in their halls of stone,
> Nine for Mortal Men doomed to die,
> One for the Dark Lord on his dark throne
> In the Land of Mordor where the Shadows lie.
> One Ring to rule them all, One Ring to find them,
> One Ring to bring them all and in the darkness bind them
> In the Land of Mordor where the Shadows lie.
>
>
> I want to print it like:-
>
> In the Land of Mordor where the Shadows lie.
> One Ring to bring them all and in the darkness bind them
> One Ring to rule them all, One Ring to find them,
> In the Land of Mordor where the Shadows lie.
> One for the Dark Lord on his dark throne
> Nine for Mortal Men doomed to die,
> Seven for the Dwarf-lords in their halls of stone,
> Three Rings for the Elven-kings under the sky,
>
> The program I wrote is
> use strict;
> my $num = $#ARGV + 1;
> my $str;
> my @file;
> if($num>= 1)
> {
>          $str = $ARGV[0];
> }
> else
> {
>          print "No argument provided\n";
> }
>
> open (FILE,$str);
> while(<FILE>)
> {
>   push(@file,$_);
> }
> print "Reversed file content\n";
> foreach(@file)
> {
>
> print pop(@file);
> }
> O/p
> perl ex_04.pl ringfile.txt
> Reversed file content
> In the Land of Mordor where the Shadows lie.
> One Ring to bring them all and in the darkness bind them
> One Ring to rule them all, One Ring to find them,
> In the Land of Mordor where the Shadows lie.
>
> I am getting only 4 lines in the output,Why I am not getting full 8
> lines in the output?
> Please help..am I doing anything wrong.

#!/usr/bin/perl
use warnings;
use strict;

my $str = shift or die "No argument provided\n";

print `tac $str`;

__END__




John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


------------------------------

Date: Mon, 14 Jun 2010 13:45:43 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: File Content reversal-Not working with foreach and pop from array
Message-Id: <87fx0ph5iw.fsf@quad.sysarch.com>

>>>>> "JWK" == John W Krahn <jwkrahn@example.com> writes:

  JWK> my $str = shift or die "No argument provided\n";

  JWK> print `tac $str`;

well, if you are going to fork out, why need the backticks and print?

	system "tac $str" ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Mon, 14 Jun 2010 16:47:03 -0700
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: File Content reversal-Not working with foreach and pop from array
Message-Id: <ZbzRn.6122$hw5.4724@newsfe04.iad>

Uri Guttman wrote:
>>>>>> "JWK" == John W Krahn<jwkrahn@example.com>  writes:
>
>    JWK>  my $str = shift or die "No argument provided\n";
>
>    JWK>  print `tac $str`;
>
> well, if you are going to fork out, why need the backticks and print?
>
> 	system "tac $str" ;

Cause then I would have to do all the system error checking (which you 
neglected to do) and besides, print() with no filehandle does not 
necessarily go to STDOUT.   :-)



John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


------------------------------

Date: Mon, 14 Jun 2010 20:25:14 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: File Content reversal-Not working with foreach and pop from array
Message-Id: <87iq5l6t1x.fsf@quad.sysarch.com>

>>>>> "JWK" == John W Krahn <jwkrahn@example.com> writes:

  JWK> Uri Guttman wrote:
  >>>>>>> "JWK" == John W Krahn<jwkrahn@example.com>  writes:
  >> 
  JWK> my $str = shift or die "No argument provided\n";
  >> 
  JWK> print `tac $str`;
  >> 
  >> well, if you are going to fork out, why need the backticks and print?
  >> 
  >> system "tac $str" ;

  JWK> Cause then I would have to do all the system error checking (which you
  JWK> neglected to do) and besides, print() with no filehandle does not
  JWK> necessarily go to STDOUT.   :-)

i didn't expect the spanish inquisition!

<cue michael palin who is always late>

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Mon, 14 Jun 2010 15:49:54 +0000 (UTC)
From: kj <no.email@please.post>
Subject: Re: File::Slurp/IO::String/wantarray interaction bug
Message-Id: <hv5j32$cu1$1@reader1.panix.com>

In <slrni16ia2.250t.willem@turtle.stack.nl> Willem <willem@turtle.stack.nl> writes:

>...Maybe you misinterpreted the
>debugger output, maybe the debugger did something strange, maybe something
>else happened.

Well, it looks that it's one of those.  To determine the calling
context I was halting the execution within the READLINE method,
and then printing the value of wantarray from the debugger prompt
like this:

  DB<1> p wantarray
1

Apparentely, in the debugger "p wantarray" always produces this
result, irrespective of the value of wantarray in the executing
program.  (That's quite the "banana peel", IMHO.) 

Poking around in the perldebug man page I discovered that the right
way to determine the calling context from within the debugger is
to use the T command:

  DB<4> T
$ = IO::String::READLINE(ref(IO::String)) called from file `t/wantarraybug.pl' line 28

The leading '$' is shorthand for "called in scalar context". 

Thanks for your post!

~K


------------------------------

Date: Mon, 14 Jun 2010 15:57:03 +0000 (UTC)
From: kj <no.email@please.post>
Subject: Re: File::Slurp/IO::String/wantarray interaction bug
Message-Id: <hv5jgf$cu1$2@reader1.panix.com>

In <87zkz12gfe.fsf@quad.sysarch.com> "Uri Guttman" <uri@StemSystems.com> writes:

>and the IO::Scalar docs disagree with your call:

>       new [ARGS...]
>           Class method.  Return a new, unattached scalar handle.  If any
>           arguments are given, they're sent to open().

>       open [SCALARREF]
>           Instance method.  Open the scalar handle on a new scalar, pointed
>           to by SCALARREF.  If no SCALARREF is given, a "private" scalar is
>           created to hold the file data.

>           Returns the self object on success, undefined on error.

>so you aren't even calling it correctly.

I'm using IO::String, not IO::Scalar.  My IO::String docs says:

       $io = IO::String->new
       $io = IO::String->new( $string )
	   The constructor returns a newly-created "IO::String"
	   object.  It takes an optional argument, which is the
	   string to read from or write into. ... 

As I described in the post before this one, what led me down the
wrong path was how I was determining the value of wantarray within
the debugger.

Thanks for your comments!

~K


------------------------------

Date: Mon, 14 Jun 2010 12:58:01 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: graphics
Message-Id: <871vc9xzrq.fsf@lifelogs.com>

On Fri, 11 Jun 2010 22:02:21 +0200 Mart van de Wege <mvdwege@mail.com> wrote: 

MvdW> Ted Zlatanov <tzz@lifelogs.com> writes:
>> On Thu, 10 Jun 2010 22:37:56 +0200 Mart van de Wege <mvdwege@mail.com> wrote: 
>> 
MvdW> I used SVG::TT:Graph to generate the graphs, Image::Magick to
MvdW> convert them to PNG, Template Toolkit to build LaTex files
MvdW> referring to the images, and LaTeX::Driver to render the LaTeX to
MvdW> PDF.
>> 
MvdW> Works like a charm, even if the toolchain is long. LaTeX::Driver is a
MvdW> bit finicky if you don't clean up your working directory though.
>> 
>> Any chance you can publish your toolchain to convert a series of PNG
>> files to a PDF file?
>> 
MvdW> Hmm. Sure thing, but it's in three fairly substantive package files. Do
MvdW> you want that posted here, or in a private mail?

MvdW> Also, I may have to anonymise our company name, which is referred to
MvdW> quite often in variables and directory/file names.

I don't know the code so I can't say how it should be packaged.  You can
send it to me if you prefer but regardless you should check with your
company about any potential copyright issues, of course.

On Fri, 11 Jun 2010 13:50:20 -0500 John Bokma <john@castleamber.com> wrote: 

JB> some time ago I wrote this:

JB> http://johnbokma.com/mexit/2009/02/24/jpeg-to-pdf-using-perl.html

JB> to create a pdf with one JPEG per page.

That was interesting too.  I am interested in the LaTeX chain because I
want that environment for the TeX capabilities, but I can use a straight
JPG->PDF converter as you posted too.

Thanks
Ted


------------------------------

Date: Mon, 14 Jun 2010 22:53:14 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: graphics
Message-Id: <86hbl5l4jp.fsf@gareth.avalon.lan>

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Fri, 11 Jun 2010 22:02:21 +0200 Mart van de Wege <mvdwege@mail.com> wrote: 
>
> MvdW> Ted Zlatanov <tzz@lifelogs.com> writes:
>>> On Thu, 10 Jun 2010 22:37:56 +0200 Mart van de Wege <mvdwege@mail.com> wrote: 
>>> 
> MvdW> I used SVG::TT:Graph to generate the graphs, Image::Magick to
> MvdW> convert them to PNG, Template Toolkit to build LaTex files
> MvdW> referring to the images, and LaTeX::Driver to render the LaTeX to
> MvdW> PDF.
>>> 
> MvdW> Works like a charm, even if the toolchain is long. LaTeX::Driver is a
> MvdW> bit finicky if you don't clean up your working directory though.
>>> 
>>> Any chance you can publish your toolchain to convert a series of PNG
>>> files to a PDF file?
>>> 
> MvdW> Hmm. Sure thing, but it's in three fairly substantive package files. Do
> MvdW> you want that posted here, or in a private mail?
>
> MvdW> Also, I may have to anonymise our company name, which is referred to
> MvdW> quite often in variables and directory/file names.
>
> I don't know the code so I can't say how it should be packaged.  You can
> send it to me if you prefer but regardless you should check with your
> company about any potential copyright issues, of course.

Hmm.

If it's for study purposes, I don't think my boss would mind. The code
is fairly tied to our specific environment, and AFAIK you're not working
for a competitor, so that's just fine.

So I'll just do a search and replace on the identifying bits. The code
is fairly straightforward, and seeing as that you probably have some
more experience in Perl than I have, you should manage just fine. The
hardest bits to understand are the bits where I transform the query
results into SVG::TT::Graph datasets. And the template files are in
Dutch of course.
 
Don't expect it to run though. For that you need the underlying
database.

If I tar it up, it'll be a few 10s of kilobytes. Is that OK to mail as
an attachment? And I suppose your email address as given in your
postings is the right one?

Mart
-- 
"We will need a longer wall when the revolution comes."
    --- AJS, quoting an uncertain source.


------------------------------

Date: Mon, 14 Jun 2010 21:34:58 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: graphics
Message-Id: <slrni1d841.m83.nospam-abuse@powdermilk.math.berkeley.edu>

On 2010-06-13, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>>>> Generating PDF might be easy (did not try it),
>>>> and it is much easier to print...
>>
>>> This isn't something I find any problems with. Most laser printers above 
>>> entry level will support PostScript printing. Some of them support PDF 
>>> printing. Most (if not all) Unix/Linux systems will have print systems 
>>> that can rasterise PostScript for non-Postscript printers.
>>
>> You have a wrong (IMO) metric of "having problems".  PS is a
>> programming language.  There is no way to "verify" PS or debug PS:
>> there is no way to know whether a given PS file will print on your
>> neighbor's PS printer except for printing it.
>>
>> Likewise, if you can rasterize PS with one version of GS, this does
>> not imply that it would rasterize with a different version of GS.
>> Basically, PS leads you in the same messy can of worms as most other
>> programming languages (only it has no debuggers or development tools).
>>
>> PDF, on the other hand, contains just DATA, not PROGRAM.
>
> There is no clear-cut boundary between data and program.

Of course there is: decidability (this is a math term; the layman's
variant would be something like a guaranteed ability to verify).

>> It must be easy to verify (never tried it); then any non-buggy
>> implementation would be able to rasterize it.

> Newer versions of Acrobat Reader won't rasterize some PDFs generated by
> Acrobat 10 years ago, because some features of early PDF versions have
> been removed in later versions. OTOH, I am not aware of any
> backwards-compatibility issues with PostScript (which also went through
> a lot less revisions, although it is older).

Given that there is not even "same-version-compatibility", so IMO it
is silly to discuss backward-compatibility.  For a recent example, see

  http://groups.google.com/group/comp.lang.postscript/browse_thread/thread/238439c8b1f7df7c

> LaTeX (or rather TeX) is a programming language, too.

TeX is.  On the other hand, it is easy (and very productive) to
operate AmS-LaTeX as a page description language.

>> It is exactly the opposite with me.  LaTeX is known to be
>> non-backward-compatible.  So I keep data in proprietary form with a
>> known script for to-LaTeX conversion.

> Who is the proprietor of your proprietary format? You?

Yes.

Yours,
Ilya


------------------------------

Date: Mon, 14 Jun 2010 14:47:04 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: How to grep using an array of patterns?
Message-Id: <87typ5mm6f.fsf@castleamber.com>

Tad McClellan <tadmc@seesig.invalid> writes:

> John Bokma <john@castleamber.com> wrote:

>> I am not talking about reputation etc. I am glad that you replied, to be
>> honest. Why do you think it's OK to write file::slurp when you mean 
>> File::Slurp?
>
> Hey! I agree with you about something!

It isn't the first time, and won't be the last, so why the surprise?

>> As a
>> regular one should, IMO, learn to stand above it, and don't get pissed
>> off at every single newbie that shows up. 
>
> I don't get pissed at every single newbie that shows up.

OK, my bad: at every single newbie that should have done a bit more
research in the eyes of the regulars.

> Usenet is a last-resort resource, not the first resort.

I agree, no question about that. I only think that in a group with
dwindling traffic it becomes annoying if quite some post just reiterate
what has been posted daily for the past years. I thought that
programming was also about seeing a problem and providing an automated
solution to it.

> Right, but it is easier to ignore when delivered nicely.

Again, you don't have to reply. If your advice is ignored, score the
poster low, and igonre his/her future posts.

> Ignoring accepted netiquette is certainly bad for our newsgroup.

So is behavior that most (I hope) wouldn't show when in public, actually
facing the newbie.

> I don't want bad for this newsgroup.

Me neither, hence my attempt to look for a solution that will reduce the
constant stream of correcting newbies. It rarely works.

>> I mean I can ask you nicely to press the shift now
>> and then as to make your postings a bit easier on the eye, 
>
> Uri's "style" annoys the hell out of me too.

So why don't you reply to his posts trying to correct him with harsh
language? OTOH, maybe my friendly request has worked. It doesn't matter
which happens since either will prove a point I made :-).

>> I do like to keep reading posts by you, Tad and several others. But it
>> gets harder and harder to pick the fruit, since too many posts are just
>> bashing newbies. 
>
> None, none!, of my followups to this thread's OP were "just" bashing.

I talk in general: too many posts IMO in this newsgroup are bashing
newbies. If you were just bashing we wouldn't have this discussion to
begin with.

> (there's that exaggeration thing yet again, your credibility with me
>  approaches zero)

Aren't too many posts here just bashing? IMO it is. You can disagree
with that, but it has nothing to do with my credibility. Maybe we have a
different definition of bashing.

> Each and every one of my followups included help (along with the
> bashing).

Help that comes with a kick in the balls is just a kick in the balls IMO.

> It is a waste of your time to try and convince me otherwise, as I've
> been here far too long to believe that your approach is better, and
> I find it hard to believe what you say anyway.

OK, well, in that case this group isn't just for me.

>> Like I wrote in an earlier post: have the
>> faq-bot post daily: "Why doesn't anyone answer my question?" with the
>> pointers to the FAQ, posting guidelines, etc. 
>
>
> Are you waiting for someone else to implement your idea for you?

Did I write that? I have no problem to provide the code. I have also no
problem to run a bot daily *but* I think it's easier to have the current
FAQ bot post one additional message. On top of that I am not going to
run a bot without approval of the majority of regulars here.

>> newbies, and more time for fun discussions. And trust me, while they
>> will ignore stuff like "posting guidelines" they will read "Why doesn't"
>> because that's the question they have ;-).
>
> I doubt that, but go ahead and try it and we'll find out.

I doubt it, since it only works if everybody in this group ignores each
question that doesn't use this group as the last resort and/or doesn't
follow the posting guidelines.

> If you are unwilling to spend 10 minutes grepping the std docs
> before asking your question on Usenet, then Usenet is better off
> if you _are_ scared away.

I thought you gave classes at Stonehenge but just read that you only
sell them. Figures.

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


------------------------------

Date: Mon, 14 Jun 2010 16:23:24 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to grep using an array of patterns?
Message-Id: <slrni1d73r.fu0.tadmc@tadbox.sbcglobal.net>

John Bokma <john@castleamber.com> wrote:

> I thought you gave classes at Stonehenge 


I do.


> but just read that you only
> sell them. 


Where did you read that? It is in error.


> Figures.


Ran out of other approaches, so resorting to ad hominem now eh?

That's sure to be convincing...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Mon, 14 Jun 2010 18:56:38 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: How to grep using an array of patterns?
Message-Id: <87pqztmamh.fsf@castleamber.com>

Tad McClellan <tadmc@seesig.invalid> writes:

> Ran out of other approaches,

To be honest, I knew from the start it would be pointless to discuss
things with asshats like you and Uri. So, good luck with your Perl
"community". I am sure the newbies will find greener pastures at Stack
Overflow or elsewhere.

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


------------------------------

Date: Mon, 14 Jun 2010 20:53:12 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to grep using an array of patterns?
Message-Id: <slrni1dmtp.gji.tadmc@tadbox.sbcglobal.net>

John Bokma <john@castleamber.com> wrote:
> Tad McClellan <tadmc@seesig.invalid> writes:
>
>> Ran out of other approaches,
>
> To be honest, I knew from the start it would be pointless to discuss
> things with asshats like you


You have slandered me in public when you said in your ad hominem attack:

    but just read that you only sell them.

Are you willing to stand behind what you have written?

Man up and tell me where you read that (if you don't, then we'll
just assume that you made it up).


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2991
***************************************


home help back first fref pref prev next nref lref last post