[23649] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5856 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 25 09:05:43 2003

Date: Tue, 25 Nov 2003 06:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 25 Nov 2003     Volume: 10 Number: 5856

Today's topics:
    Re: Assigning split to a list: undefined values? (Anno Siegel)
    Re: Avoiding running a process twice <REMOVEsdnCAPS@comcast.net>
    Re: Can this script be used to spam? <REMOVEsdnCAPS@comcast.net>
    Re: code structure <REMOVEsdnCAPS@comcast.net>
    Re: Creating UNICODE filenames with PERL 5.8 <ben.liddicott@comodogroup.com>
        creating unix-like text files in windows <huppu1@ROSKAPOSTI.yahoo.com>
    Re: creating unix-like text files in windows <hexkid@hotpop.com>
    Re: Excerpts from search result page news@roaima.freeserve.co.uk
        Fetching Thomsonfn Realtime Data <Temp@NoSuchDomain.Info>
    Re: Fetching Thomsonfn Realtime Data (Anno Siegel)
    Re: help with find2perl <sunil_franklin@hotmail.com>
    Re: help with find2perl (Anno Siegel)
    Re: module selction <REMOVEsdnCAPS@comcast.net>
    Re: Need help with a program (Anno Siegel)
    Re: newbie <STDIN> question (Anno Siegel)
    Re: newbie <STDIN> question <REMOVEsdnCAPS@comcast.net>
    Re: Perl Editor <REMOVEsdnCAPS@comcast.net>
    Re: push @arr, slice-of-href <eddhig22@yahool.com>
    Re: Regexp issue . . . <REMOVEsdnCAPS@comcast.net>
    Re: sending stdin to a shell command in perl <REMOVEsdnCAPS@comcast.net>
    Re: undif as if it is 0 (Anno Siegel)
    Re: undif as if it is 0 <REMOVEsdnCAPS@comcast.net>
    Re: undif as if it is 0 <REMOVEsdnCAPS@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Nov 2003 11:32:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Assigning split to a list: undefined values?
Message-Id: <bpvek4$cs8$4@mamenchi.zrz.TU-Berlin.DE>

Dmitry Epstein  <mitia.nospam@northwestern.edu.invalid> wrote in comp.lang.perl.misc:
> ko <kuujinbo@hotmail.com> wrote in
> news:bpme0m$25q$1@pin3.tky.plala.or.jp: 
> > Dmitry Epstein wrote:
> >> Here is a code snippet:
> >> 
> >> while ($line = <F>) {
> >>          my ($node1, $node2, $node3) = split ' ', $line;
> >>          last unless defined $node3;
> >>          ...
> >> }
> >> 
> >> The idea here was that the loop stops if the line was split
> >> into fewer than 3 values.  It doesn't work however: when the
> >> line has only 2 values, the variable $node3 is initialized
> >> with zero instead of remaining undefined.  How come?
> >> 
> >> (I have since changed the code to use an array instead of a
> >> list.) 
> >> 
> > 
> > Since the pattern ' ' is split()ing on whitespace, the newline
> > on each line results in an empty trailing field ('', which is
> > a defined value). So you need to get rid of the newline on
> > each line: 
> > 
> > use strict;
> > use warnings;
> > 
> > while (my $line = <DATA>) {
> >    chomp $line;
> >    my ($node1, $node2, $node3) = split ' ', $line;
> >    last unless defined $node3;
> >    print join(" ", $node1, $node2, $node3), "\n"
> > }
> > 
> > __DATA__
> > a s d
> > a s
> > 
> > HTH- keith
> 
> I don't think so.  Split on ' ' is supposed to "chomp" any trailing 
> whitespace.  In fact, if I use an array to store the value of split 
> instead of a list of scalars, the array does not receive a null 
> value in the end.

Quite so.

Assigning to a list (with a given number of slots) is equivalent to
supplying a limit parameter of one more than the number of slots to
split().  With a limit parameter, trailing empty fields aren't dropped.

Granted, split() is a little too clever for its own good, but it's all
in the documentation.

Anno


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

Date: Tue, 25 Nov 2003 06:13:13 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Avoiding running a process twice
Message-Id: <Xns943E498BBEF30sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
news:bpv8u5$bec$2@mamenchi.zrz.TU-Berlin.DE: 

> Simon Andrews  <simon.andrews@bbsrc.ac.uk> wrote in
> comp.lang.perl.misc: 
>> Anno Siegel wrote:
>> 
>> A nice little idea someone posted here was to get an exclusive lock
>> on the script itself to make sure only one instance was running.  I
>> never tried it, but it seemed like a nice way to do this as you don't
>> have to remember which file you're locking for a particular script,
>> you just lock the script itself.
>> 
>> Having said this, the flock documentation says that:
>> 
>> [lockf] requires that FILEHANDLE be open with write intent
> 
> Right, on some systems require this, including mainstream ones
> (solaris). That requirement is short-sighted design, imho.  It assumes
> that a file lock always protects exactly the file it is locking.  Our
> example shows that other kinds of locking occur where the requirement
> makes no sense. 

Aha!!  That clears up a longstanding confusion on my part.

Some time ago, I attended a lightning talk by Mark Dominus, in which he 
illustrated the "lock DATA" method of ensuring exclusivity.  I went to 
work the next day and tried it, on a Solaris machine.  I never got it to 
work, and I never figured out why.

Thanks, Anno.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NHeGPeouIeTNHoEQJCIACfVRer1jF1myGJQE6678HpX5AHqskAoOrC
WU+VcLgwchew922H8FD7Y4I1
=m6yK
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 06:28:29 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Can this script be used to spam?
Message-Id: <Xns943E4C2285DE2sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"David Staschover" <davezx1@yahoo.com> wrote in
news:Oiswb.38545$A%3.512977@ord-read.news.verio.net: 

> We are getting numerous bounceback messages with the following script
> in the bounced email. It appears that someone is using this script to
> send spam. Is there any way for a visitor to break this script over
> the web, changing the recipient, or added Bcc's to this message
> through a web browser? And if so, any idea how to fix it?

1. You ought to be using the CGI.pm module instead of parsing your own CGI 
input.

2. You are doing absolutely no validation of any of the CGI inputs.  It 
would be trivial for me, or anyone, to craft an HTML form on my own 
computer and type in whatever I wanted into any of the fields, and submit 
it to your script on your server.  *Never* trust CGI input.  *Always* 
validate.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NLDWPeouIeTNHoEQKZIwCgvHuvBKfHFdSIFJbIJoxXErP/ZqcAn37P
OlKdxwfqFpYGGuek/8V/u1Om
=SnX9
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 06:16:45 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: code structure
Message-Id: <Xns943E4A250DFC7sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Edo <eddhig22@yahoo.com> wrote in news:3FC1A842.6080704@yahoo.com:

> could this
> 
>   %info = prepare (%data, $field);
> 
> using the same method as you suggested be done
>    prepare (%data, $field => %info); ?

Not with prepare's prototype of \%\%.

Why *are* you using so many prototypes?  A Perl novice should almost never 
use prototypes -- heck, Perl experts almost never use them.  They're not a 
regular programming practice; they're only for forcing functions to accept 
unusual syntax in exceptional situations.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NITGPeouIeTNHoEQJ+4gCg6wz7H/m6zKa4P2yLQPCwoa0ancMAnjBc
fEyX/BoBeE/LaOhX2I5sWqZD
=qqfN
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 14:02:05 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: Creating UNICODE filenames with PERL 5.8
Message-Id: <bpvnd1$gam$1@kylie.comodogroup.com>

What you may be seeing is that STDOUT is writing UTF-8, which is being
treated as ISO-8859-1, and translated to UTF-16 for display. I haven't
managed to establish this, or come up with a workaround.

My own testing indicates that, under 5.8.0, with -C, you can read unicode
filenames correctly using glob, and then create new files with related names
which preserve the unicode chars. I haven't tested readdir, so maybe that
doesn't work. I haven't tested 5.8.1, so probably that doesn't work either.

Therefore I suggest you try "glob qq($dir/*)" instead of readdir, which
should also be reasonably portable.

Watch line wrapping:

perl -C -MFile::Copy -e "use utf8; foreach my $f (glob qq("$ARGV[0]")){print
length($f), qq($f\n); open(FILEH, $f) or die qq(Can't open $f: $!); print
<FILEH>; File::Copy::copy $f, qq($f.2.eml) }" "T*1.eml"


In other words, given a file:
    Test 1 with Attachement ? RFC2231.eml
(the squiggle is ARABIC LETTER DAD)

It successfully creates file:
    Test 1 with Attachement ? RFC2231.eml.2.eml
and prints out:
######################
39Test 1 with Attachement ??? RFC2231.eml
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
To: "ben.liddicott@comodogroup.com"
Subject: Test 1
######################

(remainder omitted, as irrellevant).

Now, 39 is the wrong length, as it appears to be counting ARABIC LETTER DAD
as three.

However, with "use bytes" instead of "use utf8", it fails altogether, with:
39Test 1 with Attachement ??? RFC2231.eml
Can't open Test 1 with Attachement ??? RFC2231.eml: No such file or
directory at -e line 1.

Clearly, something is not quite right here.

Cheers,
Ben Liddicott


"Ben Liddicott" <ben.liddicott@comodogroup.com> wrote in message
news:bpg2nf$qg7$1@kylie.comodogroup.com...
> "Allan Yates" <allan@yates.ca> wrote in message
> news:d6f51524.0311171301.168edab3@posting.google.com...
> > The key was the missing "-C". I didn't clue in from the documentation
> > that this was important. Once I added that command line parameter, the
> > file was created with the correct name.
> >
> > My next step was to read the file name from the directory. However, I
> > thought I read in some documentation somewhere that 'readdir' is not
> > UNICODE aware. I seemed to prove this by reading the directory
> > containing the file I just created. It comes back with a two character
> > file name that 'ord' into 0xd8 and 0xb6 as you indicated.
> >
> > Do you know of a method of reading directories to get the UNICODE file
> > names?




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

Date: Tue, 25 Nov 2003 14:42:58 +0200
From: "Huppu" <huppu1@ROSKAPOSTI.yahoo.com>
Subject: creating unix-like text files in windows
Message-Id: <3fc34f07@usenet01.boi.hp.com>

Hi!

I'm trying to create unix-like text files in Windows. The biggest issue is
that I need to use only linefeed instead of carriage return+linefeed. It
tried this with hex value \x0A, but it still did norman windows linebreak
LF+CR(like I was using \n).

Does anyone have any solution for this? Creating these files in unix is not
a solution... ;-)

<-_->




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

Date: 25 Nov 2003 13:15:39 GMT
From: Pedro Graca <hexkid@hotpop.com>
Subject: Re: creating unix-like text files in windows
Message-Id: <bpvklq$1smthv$1@ID-203069.news.uni-berlin.de>

Huppu wrote:
> I'm trying to create unix-like text files in Windows. The biggest issue is
> that I need to use only linefeed instead of carriage return+linefeed. It
> tried this with hex value \x0A, but it still did norman windows linebreak
> LF+CR(like I was using \n).
>
> Does anyone have any solution for this? Creating these files in unix is not
> a solution... ;-)

newbie answer -- probably gurus have a better way to do it

check binmode
  perldoc -f binmode

example program
  #!/usr/bin/perl -w
  use strict;

  open my $FILE, ">unix.txt" or die $!;
  binmode $FILE;

  print $FILE "one\n";
  print $FILE "two\n";
  print $FILE "three\n";
  print $FILE "four\n";
  print $FILE "five\n";
  close $FILE;



HTH

-- 
 .sig


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

Date: Tue, 25 Nov 2003 10:48:39 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: Excerpts from search result page
Message-Id: <7lob91-ck7.ln1@news.roaima.co.uk>

Krishna Srinivasan <krishna@multimediastudio.com> wrote:
> I also want to include excerpts from
> the returned result page with the search terms bolded

The trivial case doesn't seem to be that hard to me.

I will assume you're producing HTML results, and that you've remembered
to strip all HTML from the search results themselves.

    foreach my $summary (find_page_summaries(@search_terms)) {
	my $re = '\b(' . join ('|', @search_terms) . ')\b';
	$summary =~ s!$re!<b>$term</b>!g;
	print "<p>$summary</p>\n";
    }

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Tue, 25 Nov 2003 12:02:49 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Fetching Thomsonfn Realtime Data
Message-Id: <JxHwb.110052$Ec1.4875615@bgtnsc05-news.ops.worldnet.att.net>

Fetching Thomsonfn Realtime Data

Thomsonfn provides the most accurate real-time data. Scottrader's data is
not accurate 80% of the time. The only way for stock quote screamer is to
use Quotetracker with scottrader data and before trade, double check with
Thomsonfn.

The author of Quotetrader refused to implement thomsonfn for an unknown
reason. I wonder if anyone here knows how to fetch data from thomsonfn
real-time?

It seems to me that it uses cookies and it uses session key with its url
after each login. So the program must maintain a cookie jar and tracks what
session the server sent back




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

Date: 25 Nov 2003 12:11:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Fetching Thomsonfn Realtime Data
Message-Id: <bpvgtj$cs8$6@mamenchi.zrz.TU-Berlin.DE>

Picker Leon <Temp@NoSuchDomain.Info> wrote in comp.lang.perl.misc:
> Fetching Thomsonfn Realtime Data
> 
> Thomsonfn provides the most accurate real-time data. Scottrader's data is
> not accurate 80% of the time. The only way for stock quote screamer is to
> use Quotetracker with scottrader data and before trade, double check with
> Thomsonfn.
> 
> The author of Quotetrader refused to implement thomsonfn for an unknown
> reason. I wonder if anyone here knows how to fetch data from thomsonfn
> real-time?
> 
> It seems to me that it uses cookies and it uses session key with its url
> after each login. So the program must maintain a cookie jar and tracks what
> session the server sent back

WTF are you on about?  This is a Perl newsgrup.

Anno


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

Date: Tue, 25 Nov 2003 16:18:08 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Re: help with find2perl
Message-Id: <KBGwb.4$wz.40@news.oracle.com>

> > All,
> >     The following does not work for me.
> >
> >             find2perl  . -name \*.\* | xargs fgrep -i 'begin'
> >
> >     any pointers?
>
> No.  It's your turn first to give us pointers.
>
> What did you expect it to do.
> What does it do instead.
> Where there any error messages?
>
> It's not like you're not posting here for the first time, is it.
>
> Anno

find  . -name \*.\* | xargs fgrep -i 'begin'
  was working for me.

find2perl even with the necessary escape characters
    find2perl  . \-name \*.\* | xargs fgrep \-i \'begin\'
seems to somehow execute fgrep.

It looks like  |  is not being recognized....

Thanks,
Sunil.





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

Date: 25 Nov 2003 12:31:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: help with find2perl
Message-Id: <bpvi2n$i8h$1@mamenchi.zrz.TU-Berlin.DE>

Sunil <sunil_franklin@hotmail.com> wrote in comp.lang.perl.misc:
> > > All,
> > >     The following does not work for me.
> > >
> > >             find2perl  . -name \*.\* | xargs fgrep -i 'begin'
> > >
> > >     any pointers?
> >
> > No.  It's your turn first to give us pointers.
> >
> > What did you expect it to do.
> > What does it do instead.
> > Where there any error messages?
> >
> > It's not like you're not posting here for the first time, is it.
> >
> > Anno
> 
> find  . -name \*.\* | xargs fgrep -i 'begin'
>   was working for me.
> 
> find2perl even with the necessary escape characters
>     find2perl  . \-name \*.\* | xargs fgrep \-i \'begin\'
> seems to somehow execute fgrep.
> 
> It looks like  |  is not being recognized....

No, you must pipe the output of find2perl into perl first.  Read the
documatation.  From "perldoc find2perl"

    SYNOPSIS
                   find2perl [paths] [predicates] | perl

You can pipe *that* output into xargs.

Anno


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

Date: Tue, 25 Nov 2003 06:42:09 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: module selction
Message-Id: <Xns943E4E73DD661sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Alison <allidance2002@hotmail.com> wrote in news:3FC2C83C.3050401
@hotmail.com:

> is there a good module to plot my stock data 'bar chart' some module 
> that is known to do it all kind of thing.

I've had good results with GD::Graph.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NOQWPeouIeTNHoEQJ/ZACfVFk0xXKJhAC4FWjlew0AeodKKhQAoNG6
88GW3SXhQPfIthJ8Xrq8Ccin
=uhMr
-----END PGP SIGNATURE-----


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

Date: 25 Nov 2003 13:11:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Need help with a program
Message-Id: <bpvke1$i8h$2@mamenchi.zrz.TU-Berlin.DE>

Glenn Jackman  <xx087@freenet.carleton.ca> wrote in comp.lang.perl.misc:
> rband <rband@yahoo.com> wrote:
> >  People,
> >  
> >  Need your help with a problem.  
> >  I need a program that will
> >  1.  take two input files of strings, file1 and file2.  
> >  2.  read strings one by one from file1, and search for strings in
> >  file2 that contain the string in file1 and append these to output
> >  file3.
> 
> I'd write:
>     
>     open F1, $file1 or die "can't open $file1: $!\n";
>     open F2, $file2 or die "can't open $file2: $!\n";
>     open F3, '>', $file3 or die "can't open $file3 for writing: $!\n";
> 
>     my @lines = <F1>;
>     close F1;

You're putting linefeeds into the regexes below.

      chomp @lines;

>     my $string = join '|', @lines;

The strings in @lines could contain metacharacters.

      my $string = join '|', map quotemeta, @lines;

>     my $re = qr($string);
> 
>     while (<F2>) {
>         print F3 $_ if /$re/;
>     }
>     close F2;
>     close F3;

Anno


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

Date: 25 Nov 2003 11:13:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: newbie <STDIN> question
Message-Id: <bpvdgu$cs8$3@mamenchi.zrz.TU-Berlin.DE>

 <Default@IO_Error_1011101.xyz> wrote in comp.lang.perl.misc:
> > What if a user presses enter for the line number?
> > Please see below.
> > How will I test for that and make $linenum default to 1 ?
> > IE. what's the value of STDIN when someone just hits return?
> > So I can test for that and make default eq. to 1.
> > Or is there some automagic?
> > Thanks
> > 
> > my  $linenum;
> > ......snip...
> > 
> > print "What's your line number? [1]\n"; $linenum = <STDIN>;
> > chomp(&linenum);
> > IF (not $linenum =~ m/^\d+$/) {
> >   die "only positive integers accepted\n";
> > }
> > ......
> > 
> Ahh i'm also a newbie but this might just do the trick.
> I'd suggest waiting for other more experienced users here to verify this.
> 
> use ExtUtils::MakeMaker qw(prompt);

Ugh.  MakeMaker is for an entirely different purpose.  Yes, it happens
to export a routine "prompt()" that can be used here, but it carries
a *huge* amount of luggage that is used for makefile generation and
serves no purpose here.

Look at the Term::ReadLine module for a prompter.

Anno


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

Date: Tue, 25 Nov 2003 06:39:20 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: newbie <STDIN> question
Message-Id: <Xns943E4DF94D189sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

goldtech@worldpost.com (leegold) wrote in 
news:679db0fb.0311241242.7e2807ba@posting.google.com:

> print "What's your line number? [1]\n"; $linenum = <STDIN>;
> chomp(&linenum);
> IF (not $linenum =~ m/^\d+$/) {
>   die "only positive integers accepted\n";
> }
> .....

Please post your real code, not a re-typed copy.  How do you expect people 
to help you (in general) if you're not showing your real code?

To answer your question, why don't you print out the value and see what it 
is?  Examine it in the debugger.  The debugger is a wonderful tool for 
learning the language.
- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NNmGPeouIeTNHoEQKpOQCeJskwXUngt22QRjGWKX25qrtDh6QAoI9h
/+HfYYVChpIVvegGXUV4eqQj
=lHDI
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 06:41:16 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Perl Editor
Message-Id: <Xns943E4E4D1DD82sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Jürgen Exner" <jurgenex@hotmail.com> wrote in news:uqywb.1182$Ll3.639
@nwrddc01.gnilink.net:

> AnnMarie wrote:
>> What is the best editor for Perl CGI-Scripts?
> 
> "Real programmers "cp /dev/audio a.out" and whistle into the mike."
> (Randal L. Schwartz )

True story: in college, I knew a guy who could whistle into a phone and 
keep a 2400 baud modem connected.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NOC2PeouIeTNHoEQL7LACgxhpu+VvvpEDu4Bd4fUUI7dvIx34AoOCX
y2HE0nYDh9S1E/IYILKvyfuQ
=EPTG
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 22:12:27 +1100
From: Edo <eddhig22@yahool.com>
Subject: Re: push @arr, slice-of-href
Message-Id: <3FC3391B.5010803@yahool.com>


ok, here is my brain dump



sub scan (\%\%\%) {
     my ($dbits, $sbits, $set) = @_;
     my @kd = keys %$dbits; my @ks = keys %$sbits;
     my @vs = @$sbits{ @ks };
     for( 0 .. (@kd - @ks) ) {
     my @kdslic =  @kd[$_ .. $_+@ks-1 ];
     my @vd = @$dbits{@kdslic};
     my $tmp = check( \@vd, \@vs );
     my @k = keys %$set;
     my $max = (sort {$a <=> $b} @k)[0] || 0;
     if ( $tmp > $max ) {
         foreach my $ky ( @kdslic ){
         tie my (%slic), 'Tie::IxHash';
49:     $slic{$ky} = %$dbits{$ky};
         }
         push @{$set->{$tmp}},\%slic;
     }
     }
54:}

syntax error at path line 49, near "$dbits{"
syntax error at path line 54, near "}"

why? I tried %dbits{$ky}, $dbits{$ky} for no avail




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

Date: Tue, 25 Nov 2003 06:44:42 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Regexp issue . . .
Message-Id: <Xns943E4EE1E1E8Dsdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"MichaelC" <mickyc@NOshaSPAMw.ca> wrote in
news:d9Dwb.492453$9l5.241927@pd7tw2no: 

> Hi all.  I am having a particularly difficult time with a perl script
> that I am writing.  The problem area is a place where I need to strip
> some newlines out of a file.
> 
> My source data is text which is in paragraph form, but has line breaks
> within the paragraphs.  I need to do as much processing as possible in
> order to minimise the amount of manual changes that I have to make.

You don't say what you mean by "paragraph form".  If you're using that 
term in the usual sense, then you mean that the paragraphs have double 
newlines between them.  Is that so?  If so, Perl can read paragraph-at-a-
time for you:

    $/ = '';
    $paragraph = <>;

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NO2mPeouIeTNHoEQKl7wCgwhaYGGLKl2VuQu4P7cXtQv9C8ZQAn0K0
9YlaoVGjDaBonogRTFfOnn5h
=h9Av
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 06:19:51 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: sending stdin to a shell command in perl
Message-Id: <Xns943E4AAB7B319sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Matthew Braid <mb@uq.net.au.invalid> wrote in
news:bpu2q7$4jk$1@bunyip.cc.uq.edu.au: 

> 1) create a temp file (File::Temp is good - make sure the file is not 
> automatically removed on exit)
> 2) fork with open('|-') (look this one up in the docs given above -
> very handy)
> 3) In the child section, reopen STDOUT (and STDERR if you want) to the
> temp filehandle, then exec the program you want to run.
> 4) In the parent program, print to the child's file handle (that you
> got with the open call) the input you want to give it, then close the
> handle. 5) In the parent, seek to the start of the temp file and read
> in the output 6) Don't forget to clean up the temp file!
> 
> There's a lot of error checking you need to do (eg success of the
> open, success of the exec, handling SIGPIPE if the child dies while
> you're writing to it etc etc) but it will work without blocking
> problems (well, so far it has all the time for me :)
> 
> This method doesn't really allow for a system where the parent and
> child need to chat back and forth, but if that's the case then usually
> the program you're calling will be written to expect interaction and 
> IPC::Open2 should be OK.

Is all this really better than the OP's original method of echoing a 
string to a command pipeline within backtics?  :-)

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NJB2PeouIeTNHoEQLV8QCaA8d2n/nQJKWIpSBvfYTnRfM5XqwAnAz8
hywvD69iD+MMVH/X6djAgPwP
=fRHB
-----END PGP SIGNATURE-----


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

Date: 25 Nov 2003 12:09:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: undif as if it is 0
Message-Id: <bpvgpt$cs8$5@mamenchi.zrz.TU-Berlin.DE>

Edo  <eddhig22@yahoo.com> wrote in comp.lang.perl.misc:
> Hello
> I am getting $max = undif if nothing in @top3, but due to the way the 
> code below is written, I need it to show 0 instead.
> do I have to change the code? or there is an operator to change undif to 
> 0 in this case?

Well, that has been answered a few times ( $max ||= 0).

> thanks
> 
>      my @kd = keys %$dbits; my @ks = keys %$sbits;
>      my @vs = @$sbits{ @ks };

What are these for?  You're not using them.

> 
>      for( 0 .. 5 ) {
> 	my $tmp = 4;
> 	my $max = (sort {$b <=> $a} @top3)[0];
> 	if ( $tmp > $max ) {
> 		... code
> 	    push @top3, \%set;

You're pushing a hashref onto @top3, but you're sorting @top3 numerically.
that can't be right.

> 	}
>      }

I've said it before (different thread, same OP, I think), that sorting
is a bad method to extract a maximum.  It runs n*log n (n being the number
of elements), but a max can be extracted in n steps.

What's more, you don't need to re-calculate the maximum in the loop at all.
You only ever add elements to @top3 that you have checked to be greater
than the current maximum.  So the new maximum will always be the freshly
added element.

Anno


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

Date: Tue, 25 Nov 2003 06:34:15 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: undif as if it is 0
Message-Id: <Xns943E4D1C93040sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Edo <eddhig22@yahool.com> wrote in news:3FC337C1.8050405@yahool.com:

> Bob Walton wrote:
>>     my $max = (sort {$b <=> $a} @top3)[0]+0;
>> 
> 
> on the first round of the loop, nothing is in the @top3 which makes
> $max undef

Right.  And the next time through the loop?  You'll have a single hash 
reference in @top3.  And then another, and another.  What do you expect 
to gain by sorting hash references?

In fact, why sort at all, when you can simply keep track of the maximum 
value so far?  Sorting is slooooow.

>> BTW, please improve your indenting style.  The lack of reasonable 
>> indenting makes your program harder to follow than necessary. 
>> Thanks. 
>> 
> I have all indentaion style working good in emacs as well as when I
> copy and paste
> 
> using the mouse button3 but when I post  it changes the indention, I 
> have no control over
> 
> this unless I am missing somthing.

Yes.  Tabs.  Tabs don't work well over Usenet.  (Imho, they don't work 
well *anywhere*).

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NMZ2PeouIeTNHoEQKgwQCgxLN9vfK4UIROKrrCjvBp5VOFiOUAoO3h
bFyJ5SOTex+3kSb2fG+UO07O
=eqdd
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Nov 2003 06:35:07 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: undif as if it is 0
Message-Id: <Xns943E4D422EA32sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Edo <eddhig22@yahoo.com> wrote in news:3FC25AF6.7010004@yahoo.com:

> Hello
> I am getting $max = undif if nothing in @top3, but due to the way the 

"undef", please.  English may not be your primary language -- that's okay 
-- but please try to be precise in your use of technical terms.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8NMm2PeouIeTNHoEQLMzwCgj8rqI7ZCgy0/br8EaHS16qiWAAwAoIXI
1tyuHOFpUoJlI+e/B8yhsyyA
=wErS
-----END PGP SIGNATURE-----


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

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:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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 V10 Issue 5856
***************************************


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