[23303] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5523 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 18 14:05:50 2003

Date: Thu, 18 Sep 2003 11:05:08 -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           Thu, 18 Sep 2003     Volume: 10 Number: 5523

Today's topics:
        ASN.1 source reader <tomas.kukosa@siemens.com>
    Re: ASN.1 source reader (Helgi Briem)
    Re: current path <paanwa@hotmail.com>
    Re: current path (Tad McClellan)
    Re: DBI.pm fetchrow() issue <shondell@cis.ohio-state.edu>
        Don't use glob() in a scalar context (was Re: opening a (Randal L. Schwartz)
        Intermediate Page w/ CGI Script (Pete Butler)
    Re: Intermediate Page w/ CGI Script <asu1@c-o-r-n-e-l-l.edu>
    Re: Intermediate Page w/ CGI Script <xx087@freenet.carleton.ca>
    Re: list-parsing problem (Tom)
    Re: list-parsing problem <uri@stemsystems.com>
        New perl programmer <materialised@ntlworld.com>
    Re: New perl programmer (Helgi Briem)
    Re: Opening file units recursively (Tad McClellan)
    Re: OT:  WebGUI, any reviews? <jl@teamlinux.de>
        Parsing A Report (raven)
        perl lib all over the place <samj@austarmetro.com.au>
    Re: perl sub and perl modules (fabre)
    Re: perl sub and perl modules <grazz@pobox.com>
    Re: perl sub and perl modules (Tad McClellan)
    Re: Quoting "$vars" and open() (Chris Marshall)
    Re: Quoting "$vars" and open() (Tad McClellan)
    Re: Regex to detect patterns that do not start with //  (Mike Grandmasion)
        sort  issue (Bogdan)
    Re: sort  issue <mpapec@yahoo.com>
    Re: sort  issue (Tad McClellan)
    Re: Splitting up an XML File (JAG)
    Re: string to integer (Tad McClellan)
    Re: WWW::Mechanize click() returns "Unexpected field va (Randal L. Schwartz)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Sep 2003 15:21:02 +0200
From: Tomas Kukosa <tomas.kukosa@siemens.com>
Subject: ASN.1 source reader
Message-Id: <3F69B13E.444B4AC7@siemens.com>

Hello,
  does anybody know any way how to read ASN.1 source into Perl?
I can not find any ASN.1 parser.

The next way can be ASN.1 -> XML -> Perl but I did not find any ASN.1 ->
XML convertor which keeps all ASN.1 information in XML.
E.g. ASN2XSD tool from obj-sys.com loses information about extension
mark position.

  Thanks,
    Tom


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

Date: Thu, 18 Sep 2003 13:20:18 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: ASN.1 source reader
Message-Id: <3f69b0cc.249320083@News.CIS.DFN.DE>

On Thu, 18 Sep 2003 15:21:02 +0200, Tomas Kukosa
<tomas.kukosa@siemens.com> wrote:

>Hello,
>  does anybody know any way how to read ASN.1 source into Perl?
>I can not find any ASN.1 parser.
>
>The next way can be ASN.1 -> XML -> Perl but I did not find any ASN.1 ->
>XML convertor which keeps all ASN.1 information in XML.
>E.g. ASN2XSD tool from obj-sys.com loses information about extension
>mark position.

Use the Bioperl modules.  They have parser to and from
every common biological data format, including ASN.1

See www.bioperl.org for further info.
--
Helgi Briem  hbriem AT simnet DOT is

Excuse the munged address.  My last
e-mail address was killed by spammers.


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

Date: Thu, 18 Sep 2003 11:44:33 -0400
From: "Paanwa" <paanwa@hotmail.com>
Subject: Re: current path
Message-Id: <3f69d2e0$0$52150$a0465688@nnrp.fuse.net>


> Perl is not CGI.
>
> The OP made no mention of what environment his Perl program runs in...

Hi Tad,

Thanks for pointing this out.  I've not yet seen an environment with ENV
can't return the script path - there are always exceptions.  Can anyone tell
me if there are performance consideration in using ENV vs Cwd?

PAW




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

Date: Thu, 18 Sep 2003 11:27:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: current path
Message-Id: <slrnbmjn71.bkh.tadmc@magna.augustmail.com>

Paanwa <paanwa@hotmail.com> wrote:
> 
>> Perl is not CGI.
>>
>> The OP made no mention of what environment his Perl program runs in...
> 
> Hi Tad,
> 
> Thanks for pointing this out.  


Is your Perl programming running in the CGI environment or is it not?


> I've not yet seen an environment with ENV
> can't return the script path - 


I have no idea what you are talking about.

We have asked you before to clarify what you meant by "script path",
please try and do that.

I can't tell if you want the current working directory, or the
location of your program file in the filesystem, or the URL for
some CGI program.

Which one is it that you are trying to find?

There are potentially lots and lots of environment variables,
which one is it that you are talking about? I assumed it
was $ENV{PWD}...


> there are always exceptions.  Can anyone tell
> me if there are performance consideration in using ENV vs Cwd?


Now I am even more confused about what it is that you are asking.

If you are asking about the "current working directory", then why
do you keep mentioning the location of the program file?

Where your program file exists in the filesystem is not related
to what your current working directory is.

We must understand what you are asking for before we can help
you find it.

Try again explaining what it is that you are asking for.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 18 Sep 2003 10:40:13 -0400
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: DBI.pm fetchrow() issue
Message-Id: <xcwwuc640tu.fsf@psi.cis.ohio-state.edu>

Bob Walton <bwalton@rochester.rr.com> writes:

> superfly2 wrote:
(snip) 
> >   while(my $val = $sthv->fetchrow())
> 
> ---------------------------^^^^^^^^
> 
> Uh, are you sure?  DBI does not contain a method called
> "fetchrow". 

Although not in the documentation, a brief search in DBI.pm shows this
line in the list of methods...

fetchrow          => undef, # old alias for fetchrow_array

(This is DBI version 1.2)

Ryan
-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


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

Date: Thu, 18 Sep 2003 16:16:51 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Don't use glob() in a scalar context (was Re: opening a file whose letter case is unknown)
Message-Id: <deda31c5a9ade798bbecc2137ff6ec19@news.teranews.com>

>>>>> "Sam" == Sam Holden <sholden@flexal.cs.usyd.edu.au> writes:

Sam> my $file = glob('[Aa][Bb][Cc]');

Don't use glob in a scalar context, as it maintains state.  Consider
the output (on a Unix system) of:

        for (1..10) {
                my $passwd = glob '/etc/passw[d]';
                if ($passwd) {
                        print "found it at $passwd\n";
                } else {
                        print "not found!\n";
                }
        }

Every other time, it will print "not found", because it didn't find
*another* one.

You want

        my ($file) = glob('[Aa][Bb][Cc]');

to get the first one (if any) discarding all others.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 18 Sep 2003 08:06:16 -0700
From: pmbutler@attbi.com (Pete Butler)
Subject: Intermediate Page w/ CGI Script
Message-Id: <9b766f0.0309180706.3bf607b@posting.google.com>

I'm working on a CGI application using Perl.  My client would like the
user to get some sort of "processing request" page immediately upon
clicking "Submit", because right now, he occasionally sees a delay
between clicking "Submit" and getting the results page.  Is there a
good way to do this with CGI?

The options I've been able to think of all have serious problems. 
Giving the user an immediate "thank you" page then processing the data
behind the scenes (as a seperate thread?  as a scheduled task?) sucks
because the page the user gets is dependant upon the information
passed in.  (Certain data gets a "sorry, not interested" page.)

I thought of making a CGI script that makes a quick-n-dirty "Thank
you!" page that has all the data submitted by the user in hidden form
elements which then submits itself, but that depends on the user
having Javascript enabled, AND would require at least a moderately
sophisticated script to power it, since the data set coming back from
the user will be dynamic based on a few configurable items.

And, of course, both options above require me to fire off a CGI script
in the first place.  Since I suspect that the performance issues
driving my client's request are caused by starting CGI scripts when
the server is under load, I suspect we'd go from this scenario:

-Press Submit
-Wait wait wait
-See results page

To this one:

-Press Submit
-Wait wait wait
-See "please wait" page
-Wait wait wait
-See results page

Is there a solution here I'm overlooking?  (Short of using mod_perl or
fastcgi to improve performance, which aren't available to me.  Or
switching to PHP; it's too late in the game for me to re-write
everything from the ground up.)

Or am I going to have to stick to my guns and insist that it's just a
part of the whole CGI experience, and that the client needs to live
with it?

(And for those of you who like a little garnish of irony, I've been
unable to replicate the performance problems my client is complaining
about in the first place.)

Thanks for your help,
-- Pete Butler


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

Date: 18 Sep 2003 15:44:35 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Intermediate Page w/ CGI Script
Message-Id: <Xns93FA77767D91Basu1cornelledu@132.236.56.8>

pmbutler@attbi.com (Pete Butler) wrote in 
news:9b766f0.0309180706.3bf607b@posting.google.com:

> I'm working on a CGI application using Perl.  My client would like the
> user to get some sort of "processing request" page immediately upon
> clicking "Submit", because right now, he occasionally sees a delay
> between clicking "Submit" and getting the results page.  Is there a
> good way to do this with CGI?

http://www.stonehenge.com/merlyn/WebTechniques/col20.html

> Or am I going to have to stick to my guns and insist that it's just a
> part of the whole CGI experience, and that the client needs to live
> with it?

Personally, I would then never do business with you again.

> (And for those of you who like a little garnish of irony, I've been
> unable to replicate the performance problems my client is complaining
> about in the first place.)

That does not mean anything.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: 18 Sep 2003 16:49:46 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Intermediate Page w/ CGI Script
Message-Id: <slrnbmjoi2.c5h.xx087@smeagol.ncf.ca>

Pete Butler <pmbutler@attbi.com> wrote:
>  I'm working on a CGI application using Perl.  My client would like the
>  user to get some sort of "processing request" page immediately upon
>  clicking "Submit", because right now, he occasionally sees a delay
>  between clicking "Submit" and getting the results page.  Is there a
>  good way to do this with CGI?

If your web server supports it, use a non-parsed headers script
    http://www.linux.psu.ru/pub/texts/ebooks/OreillyCD/web/cgi/ch03_08.htm
Then, html will be displayed as the server serves it.

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: 18 Sep 2003 06:52:25 -0700
From: tom@ztml.com (Tom)
Subject: Re: list-parsing problem
Message-Id: <59b4279a.0309180552.5f4f2f8@posting.google.com>

Abigail <abigail@abigail.nl> wrote in message news:<slrnbmj0rq.9rt.abigail@alexandra.abigail.nl>...
> Marcus Claesson (m.claesson@student.ucc.ie) wrote on MMMDCLXX September
> MCMXCIII in <URL:news:e818c15b.0309180119.47e7d9c9@posting.google.com>:
> ^^  Hi People,
> ^^  
> ^^  I have a silly little list-parsing problem that I can't get my head
> ^^  around, and I'm sure some of you have come across it before.
> ^^  
> ^^  I have a list like this:
> ^^  
> ^^  1	a
> ^^  2	b
> ^^  2	c
> ^^  3	a
> ^^  4	d
> ^^  4	d
> ^^  4	e
> ^^  4	f
> ^^  5	g
> ^^  
> ^^  and I want to make the first column non-redundant and collect the
> ^^  second column values on the same line, like this:
> ^^  
> ^^  1	a
> ^^  2	b,c
> ^^  3	a
> ^^  4	d,e,f
> ^^  5	g
> ^^  
> ^^  Please note that line 4 only has one 'd'.
> ^^  
> ^^  I've tried with both hashes and arrays (don't want to confuse you so I
> ^^  won't display them here), but nothing really works...
> 
> I saw a few solutions, but neither of them tried to keep the order
> of the input as much as possible. The following solution does:
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my (@keys, %data);
> 
> while (<DATA>) {
>     chomp;
>     my ($key, $value) = split /\s+/ => $_, 2;
>     push @{$data {$key}} => $value;
>     push @keys => $key;
> }
> 
> my %h;
> foreach my $key (grep {!$h {$_} ++} @keys) {
>     my %h;
>     print "$key   ", join (", " => grep {!$h {$_} ++} @{$data {$key}}), "\n";
> }
> 
> 
> __DATA__
> 1       a  
> 2       b
> 2       c
> 3       a
> 4       d
> 4       d
> 4       e 
> 4       f
> 5       g
> 
> 
> 
> Abigail

I think the solutions that used only hash are easier to visualize than
the hash/array combination as shown. Perhaps with the changes to those
solutions will also keep the order of the input as much as possible:

#!/usr/bin/perl
use strict;

my (%data,%list);
while (<DATA>)
{
    next unless /(\w+)\s+(\w+)/; # skip if format is not as specified

	if(!$data{"$1$2"}) # add to list only if not already saved
	{
		if($list{$1}) { $list{$1} .= "," } # add comma separator
		$list{$1} .= $2;
	}
	$data{"$1$2"}++;	
}
foreach my $k(sort keys %list)
{
	print "$k\t$list{$k}\n";
}

__DATA__
1       a
2       b
2       c
3       a
4       d
4       d
4       e
4       f
5       g

Tom
ztml.com


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

Date: Thu, 18 Sep 2003 16:17:05 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: list-parsing problem
Message-Id: <x7llsmt6ke.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS>     while ( <DATA> ) {
  AS>         my ( $first, $second) = split;
  AS>         undef $coll{ $first}->{ $second}; # undef brings the key to existence

that is the single ugliest use of undef i have ever seen!!

i will have to copy that for some future talk at yapc: "where to not use
undef"

:)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class


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

Date: Thu, 18 Sep 2003 14:10:02 +0100
From: Materialised <materialised@ntlworld.com>
Subject: New perl programmer
Message-Id: <bkcaut$318l$2@ID-204621.news.uni-berlin.de>

Hi Im looking for the FAQ for the NG if someone can help me out please :)



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

Date: Thu, 18 Sep 2003 13:18:53 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: New perl programmer
Message-Id: <3f69b0a3.249279034@News.CIS.DFN.DE>

On Thu, 18 Sep 2003 14:10:02 +0100, Materialised
<materialised@ntlworld.com> wrote:

>Hi Im looking for the FAQ for the NG if someone can 
> help me out please :)

http://mail.augustmail.com/~tadmc/clpmisc.shtml

For more information about netiquette in general, see the 
"Netiquette Guidelines" at:

http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

Good luck.
--
Helgi Briem  hbriem AT simnet DOT is

Excuse the munged address.  My last
e-mail address was killed by spammers.


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

Date: Thu, 18 Sep 2003 08:32:26 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Opening file units recursively
Message-Id: <slrnbmjcva.ai1.tadmc@magna.augustmail.com>

John Ramsden <john_ramsden@sagitta-ps.com> wrote:

> However, I am having a lot of trouble getting the file units
> to open and close properly. The following is a short extract
> of the relevant code, which works apart from the fact that
> when wd_runcr() tries to close the 'include'd file the next
> level file turns out to be closed at the same time.


Because $fileunit is a "package variable" (ie. a global variable).

The "inner" recursive subroutines are messing up the values of
variables used by the outer iterations.


> Why do Perl file units 


What is a "file unit"?

Do you mean "filehandle"?

Do you mean "file descriptor"?

Do you mean something else?


> the guy who first developed the language 


"the guy" has a name. It is Larry.


> (I've also tried 'our' instead of 'local' No idea what
> either does,


That is the cause of your problem, so you better keep at it until
you do understand them. These may help with that:

   "Coping with Scoping":

      http://perl.plover.com/FAQs/Namespaces.html

and

   perldoc -q filehandle

       How can I pass/return a {Function, FileHandle, Array,
       Hash, Method, Regex}?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 18 Sep 2003 10:05:47 +0200
From: Jochen Lillich <jl@teamlinux.de>
Subject: Re: OT:  WebGUI, any reviews?
Message-Id: <e0pbkb.8c7.ln@lnxsrv3.teamlinux.de>

Prabh wrote:

> I'm trying to find any reviews for the open-source , content
> management system, WebGUI and am unable to find many.
> I'm interested to know if any of you here have used it and your
> experiences with it.

I like it and use it on a growing number of websites. I also recently wrote
an article about it for the German "Linux Magazin". It's a CMS just as
simple as to do the job. There are more and more available dynamic page
elements ("Wobjects"), so you can easily and rapidly build a website with
many pages of different dynamic content such as articles with comments,
forums, weblogs, polls, file downloads etc. If you're looking for a CMS
more flexible than the PHPNuke style portal systems I'd recommend having a
look. 

Best regards,

  Jochen



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

Date: 18 Sep 2003 09:43:02 -0700
From: raven_riverwind@yahoo.com (raven)
Subject: Parsing A Report
Message-Id: <7270d1f8.0309180843.68bbcf74@posting.google.com>

I have a system report that some of you may be familiar with. It is
the output from the print_manifest command on an HP-UX system with
ignite installed. There are divisions in the text file that I am
trying to break up, but feel like I am going about wrong. I am trying
to extract the block of text within 'Installed Software' up to the
next major heading. Can someone check my work and comment? Thanks. See
below:

Report:

Installed Software

    Your system was installed with HP-UX version B.11.11.

    Your system has the following software products installed and 
    configured on the system disk drive(s).  

    Product          Revision          Description
    B2491BA          B.11.11           MirrorDisk/UX
    B3701AA          C.03.25.00        HP GlancePlus/UX Pak for s800
11i
    B3913DB          C.03.30.01        HP aC++ Compiler (S800)
    B5725AA          B.3.3.116         HP-UX Installation Utilities
(Ignite-UX)
    B6834AA          B.01.00           HP-UX Security Patch Check Tool
    B9901AA          A.03.05           HP IPFilter 3.5alpha5
    BUNDLE11i        B.11.11.0102.2    Required Patch Bundle for HP-UX
11i, February 2001
    CDE-English      B.11.11           English CDE Environment
    FDDI-00          B.11.11.01        PCI FDDI;Supptd
HW=A3739A/A3739B;SW=J3626AA
    FibrChanl-00     B.11.11.06        PCI/HSC FibreChannel;Supptd
HW=A6684A,A6685A,A5158A
    GigEther-00      B.11.11.14        PCI/HSC GigEther;Supptd
HW=A4926A/A4929A/A4924A/A4925A;SW=J1642AA
    HPUX11i-OE       B.11.11.0106      HP-UX 11i Operating Environment
Component
    HPUXBase64       B.11.11           HP-UX 64-bit Base OS
    HPUXBaseAux      B.11.11.0106      HP-UX Base OS Auxiliary
    HWEnable11i      B.11.11.0106.8    Hardware Enablement Patches for
HP-UX 11i, June 2001
    Ignite-UX-11-11  B.3.3.116         HP-UX Installation Utilities
for Installing 11.11 Systems
    J4189-11001B     E.10.18           Hewlett-Packard JetDirect
Printer Installer for Unix
    OnlineDiag       B.11.11.03.08     HPUX 11.11 Support Tools
Bundle, Jun 2001
    RAID-00          B.11.11.01        PCI RAID; Supptd HW=A5856A


LVM File System Configuration

    This system is configured with Logical Volume Manager (LVM) file
systems.
    Refer to the File System layout section for information on the LVM
layout.


JFS File System Configuration

    This system is configured with a Journaled File System (referred
to
    as either JFS or VXFS).  Refer to the File System layout section
for
    information on JFS/VXFS file systems.


Code:

#!/usr/contrib/bin/perl -w

open SOFTWARE, "system.txt" or die "Cannot open file!";

$flag = 0;
while (<SOFTWARE>) {
        if (/^Installed Software/) {
                $flag = 1;
                next;
        }               
        if ($flag) {
                last if (/^\w+/);       
                # Where we do the work.
        }
}


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

Date: Thu, 18 Sep 2003 15:02:24 GMT
From: "Sam" <samj@austarmetro.com.au>
Subject: perl lib all over the place
Message-Id: <3f69c8ff@news.comindico.com.au>

Hello

I have Perl modules all over the place and I think it would be good house
keeping practice to get them all in one common dir. If that is true then how
can I do that?

Or just keep adding "use lib "/my/location";" at the top of the programs?



I have some module.pm in the following locations

/usr/local/lib/perl/5.6.1

/usr/lib/perl/5.6.1

/usr/local/lib/perl5/5.8.0/i686-linux

/usr/local/lib/perl5/5.8.0

/usr/local/lib/perl5/site_perl/5.8.0/i686-linux

/usr/local/lib/perl5/site_perl/5.8.0

/usr/local/lib/perl5/site_perl



thanks




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

Date: Thu, 18 Sep 2003 14:10:17 +0100
From: pedro.fabre@gen.gu.se (fabre)
Subject: Re: perl sub and perl modules
Message-Id: <pedro.fabre-1809031410170001@192.168.0.5>

But in the case I want to change the values to upper case or modify them,
then I will need to use indexes in perl. right?


sub toUpperCase {
    my (@arr) =@_;

    for my $i (0..$#arr){ 
        for my $j (0..$#{$arr[$i]}){ 
            $arr[$i][$j] =~ tr/[a-z]/[A-Z]/;   # convert to upper case 
        }
    }
}

that doesn't work either.

how this will work passing as references?

Thanks

P

PS: I cam from java and migrate to perl seems to be not an easy task!

In article <bkc7j5$2un$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> fabre <pedro.fabre@gen.gu.se> wrote in comp.lang.perl.misc:
> > Hi all,
> > 
> > 
> > I am new in perl and I am having some difficulties in getting used to it.
> > I have an array of array:
> > 
> > my @hap = (
> >      [qw/ a c g t g c/],
> >      [qw/ c g ? t a g/],
> >      [qw/ a c t t ? c/]);
> > 
> > 
> > and as during the process I will need to print how this evolves during the
> > process, I tried to place a print sub:
> > 
> > 
> > sub MyPrint {
> >     my (@arr) =@_;
> > 
> >     for my $i (0..$#arr){
> >         for my $j (0..$#{$arr[$i]}){
> >             print $arr[$i][$j]."\t";
> >         }
> >         print "\n";
> >     }
> > }
> 
> That's more complicated than it has to be.  Don't use array indices in
> Perl unless you have to.  Here is a simplified version:
> 
>     sub MyPrint {
>         for ( @_ ) {
>             print join( "\t", @$_), "\n";
>         }
>     }
> 
> 
> > 
> > 
> > if I call my print as reference:
> > 
> > MyPrint(\@hap);
> > I get:
> >
> > ARRAY(0x541c)   ARRAY(0x7b944)  ARRAY(0x7b884)
> > 
> > instead if I pass the array as value:
> > 
> > MyPrint(@hap);
> > 
> > I get the answer I was trying to get.
> > 
> > a       c       g       t       g       c
> > c       g       ?       t       a       g
> > a       c       t       t       ?       c
> > 
> 
> Sure.  That calls MyPrint with a single scalar parameter, which is
> a listref.  The way you layed out the routine, it expects a list
> (of listrefs).
> 
> > But As I think that passing as value (creates a variable that we are not
> > going to use anymore ) I think the best idea was passing by reference,
> > but..
> > 
> > How I do that?
> 
> To make it work with a reference, change the loop control in "for"
> 
>     sub MyPrint {
>         for ( @{ shift()} ) {
>             print join( "\t", @$_), "\n";
>         }
>     }
> 
> > Alternatively I was thinking to place My sub in a module. How this will
> > work on that situation?
> 
> You would define the routine in a module exactly the way you do it
> in your main file.
> 
> Anno


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

Date: Thu, 18 Sep 2003 14:16:12 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: perl sub and perl modules
Message-Id: <M6jab.3735$U6.318@nwrdny03.gnilink.net>

fabre <pedro.fabre@gen.gu.se> wrote:

[ don't top post ]

> But in the case I want to change the values to upper case or modify 
> them, then I will need to use indexes in perl. right?

No!
 
It's much easier (and more efficient) to loop over the arrays directly,
rather than looping over temporary lists of indices.

  sub to_upper {
    for my $ref (@_) {
      $_ = uc for @$ref;
    }
  }

> PS: I cam from java and migrate to perl seems to be not an easy task!

You just have to lose your taste for doing things the "hard way".

-- 
Steve


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

Date: Thu, 18 Sep 2003 09:56:42 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl sub and perl modules
Message-Id: <slrnbmjhta.au9.tadmc@magna.augustmail.com>


[ Please do not top-post.  Please do not full-quote. ]


fabre <pedro.fabre@gen.gu.se> wrote:
> But in the case I want to change the values to upper case or modify them,
> then I will need to use indexes in perl. right?


Wrong.


> sub toUpperCase {
>     my (@arr) =@_;
> 
>     for my $i (0..$#arr){ 
>         for my $j (0..$#{$arr[$i]}){ 
>             $arr[$i][$j] =~ tr/[a-z]/[A-Z]/;   # convert to upper case 


tr/// does not respect locales, so it does NOT convert to upper case,
it converts characters.

Why are you asking tr/// to replace "[" with "[" and "]" with "]" ?


>         }
>     }
> }
> 
> that doesn't work either.


It worked when I tried it, so I can't help you with that part.


> PS: I cam from java and migrate to perl seems to be not an easy task!


Perl has many operators that operate on lists (such as foreach), so
you very seldom _need_ to do explicit indexing yourself. 

You are human, you may make a mistake. 

perl is a machine, it will do the right thing everytime.

You should catch yourself whenever you find yourself doing explict
indexing, you are likely thinking in some other language and there
is a more Perlish way of accomplishing the same thing.

You can rewrite your uppercasing to have perl do the indexing
for you too:

-----------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @hap = (
      [qw/ a c g t g c/],
      [qw/ c g ? t a g/],
      [qw/ a c t t ? c/]);

toUpperCase(@hap);
print Dumper \@hap;


sub toUpperCase {
    my (@arr) =@_;

    foreach my $aref ( @arr ){
        foreach my $value ( @$aref ){
            $value = uc $value;
        }
    }
}
-----------------------------------------




[ snip 90 lines of TOFU ]

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 18 Sep 2003 06:59:09 -0700
From: c_j_marshall@hotmail.com (Chris Marshall)
Subject: Re: Quoting "$vars" and open()
Message-Id: <cb9c7b76.0309180559.5cf3ba30@posting.google.com>

sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message 
> > How about when using open() to write to a file. e.g.
> 
> Then you use quotes obviously, since it is a completely different case.
> 
> ">$vars" is completely different than "$vars".
> 
> [snip silly example]


Well calling it silly is a bit harsh.

The whole basis for my question was:
1) the faq says not to enclose a $var in quotes
2) when you open a file for writing you are tempted to do just that.

Anyway - the 3 parameter form of open() is just what I was looking for
and if ">$vars" is perfectly safe then even better.

Cheers,
Chris


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

Date: Thu, 18 Sep 2003 09:41:39 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quoting "$vars" and open()
Message-Id: <slrnbmjh12.au9.tadmc@magna.augustmail.com>

Chris Marshall <c_j_marshall@hotmail.com> wrote:
> sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message 
>> > How about when using open() to write to a file. e.g.
>> 
>> Then you use quotes obviously, since it is a completely different case.
>> 
>> ">$vars" is completely different than "$vars".
>> 
>> [snip silly example]
> 
> 
> Well calling it silly is a bit harsh.
> 
> The whole basis for my question was:
> 1) the faq says not to enclose a $var in quotes


It was "silly" because it did not illustrate the situation that
the FAQ is talking about.

If your question was about a Perl FAQ, it would have been helpful
to point that out said FAQ, it would have avoided some of the 
resulting misunderstandings...


> 2) when you open a file for writing you are tempted to do just that.


No you're not.

You are tempted to do ">$var", which is *not* what the FAQ is talking about.

You have misunderstood the FAQ.

What is "bad" is quoting when the *only thing* quoted is a
scalar variable.

The FAQ says that

   "$var"

is wrong. The FAQ does not say anything about

   ">$var"


> Anyway - the 3 parameter form of open() is just what I was looking for


"$var" being "wrong" has nothing to do with open().

   print "$var";

is just as wrong.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 18 Sep 2003 11:01:50 -0700
From: surfer97301@yahoo.com (Mike Grandmasion)
Subject: Re: Regex to detect patterns that do not start with // or <!--
Message-Id: <75821f06.0309181001.377b455b@posting.google.com>

> m{^(?!//|<!--).*the }

Yeah I would have though I could negate a grouping like that too but
if I change my pattern from:

 'out.print.*?[^/][^/].*?the'

to

 'out.print.*?^(//).*?the'

I get no output.


> --  This is my pattern so far,
> --  
> --  grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
> --  'out.print.*?[^\<][^!][^-][^-].*?the'
> 
>     $ perl -w    
>     grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
>     String found where operator expected at - line 1, near "PRi 'out.print.*?[^/][^/].*?the'"
>             (Do you need to predeclare PRi?)
>     'out.print.*?[^\<][^!][^-][^-].*?the'
>     String found where operator expected at - line 2, near "Pi
>     'out.print.*?[^\<][^!][^-][^-].*?the'"
>             (Missing semicolon on previous line?)
>     syntax error at - line 1, near "PRi 'out.print.*?[^/][^/].*?the'"
>     Execution of - aborted due to compilation errors.
>     $
> 
> 
> Well, that doesn't compile.

Right it is using a perl regular expression being executed through
grep on the unix commandline.

> "sort of works"? Is that like "partially pregnant"?

No more like thinking you are pregnant with a baby and finding out you
are pregnant with two.  My pattern is returing a little more than I
want.

Specifically I get hits on it like this:

out.print("<!--\r\n\t

because I assume that the pattern puts the <!-- into the minimal match
before the ^(<!--) portion.

Mike


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

Date: 18 Sep 2003 09:07:00 -0700
From: bogdan_czyz@hotmail.com (Bogdan)
Subject: sort  issue
Message-Id: <98bf9157.0309180806.bbb1955@posting.google.com>

Hi there, 
I need to sort elements of of list/array by character. For instance I
got "hdisk1 hdisk10 hdisk11 hdisk2 hdisk3 ... " and need to have
"hdisk1 hdisk2 hdisk3 ... hdisk10 hdisk11 ..."
I can do that using external programs like 
$ cat file_with_hdisks | sort -n -k1.6 

but I'd like to do it in perl. Does anyone have any piece of code or
at least idea how to achieve that in as easy way as passible?

Thanks,
Bogdan


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

Date: Thu, 18 Sep 2003 18:29:35 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: sort  issue
Message-Id: <93njmvsfnd80796n71b2s497op4cfnukgo@4ax.com>

X-Ftn-To: Bogdan 

bogdan_czyz@hotmail.com (Bogdan) wrote:
>Hi there, 
>I need to sort elements of of list/array by character. For instance I
>got "hdisk1 hdisk10 hdisk11 hdisk2 hdisk3 ... " and need to have
>"hdisk1 hdisk2 hdisk3 ... hdisk10 hdisk11 ..."
>I can do that using external programs like 
>$ cat file_with_hdisks | sort -n -k1.6 
>
>but I'd like to do it in perl. Does anyone have any piece of code or
>at least idea how to achieve that in as easy way as passible?

http://www.google.com/search?q=schwartzian

#untested
my @arr = qw/hdisk1 hdisk10 hdisk11 hdisk2 hdisk3/;
@arr = 
  map $_->[0],
  sort {
    $a->[1] cmp $b->[1] ||
    $a->[2] <=> $b->[2]
  }
  map [ $_, /(\w+)(\d+)/ ], @arr;



-- 
Matija


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

Date: Thu, 18 Sep 2003 11:36:46 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sort  issue
Message-Id: <slrnbmjnou.bkh.tadmc@magna.augustmail.com>

Bogdan <bogdan_czyz@hotmail.com> wrote:

> I need to sort elements of of list/array by character. For instance I
                                ^^^^^^^^^^
> got "hdisk1 hdisk10 hdisk11 hdisk2 hdisk3 ... " 


That is not a "list/array", that is a string.


> and need to have
> "hdisk1 hdisk2 hdisk3 ... hdisk10 hdisk11 ..."


There are several Frequently Asked Questions about sorting,
have you already seen their answers?


> I can do that using external programs like 
> $ cat file_with_hdisks | sort -n -k1.6 


Why are you stopping at the 6th character when some of your pieces
have 7 characters?  (eg. hdisk10).

You have a Useless Use Of Cat as well:

   sort -n -k1.6 file_with_hdisks


> but I'd like to do it in perl. Does anyone have any piece of code or
> at least idea how to achieve that in as easy way as passible?


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

my @parts =  split /\s+/, 'hdisk1 hdisk10 hdisk11 hdisk2 hdisk3';
print "$_\n" for @parts;  # before
print "----\n";

@parts = sort { substr($a, 5) <=> substr($b, 5) } @parts;
print "$_\n" for @parts;  # after
---------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 18 Sep 2003 08:33:27 -0700
From: jeffg@programmer.net (JAG)
Subject: Re: Splitting up an XML File
Message-Id: <6b40b6b9.0309180733.6cdcb2c8@posting.google.com>

toddrw69@excite.com (trwww) wrote in message news:<d81ecffa.0309171902.596dfa99@posting.google.com>...
> jeffg@programmer.net (JAG) wrote in message news:<6b40b6b9.0309171009.20d66b6a@posting.google.com>...
> > I have an XML file that looks like this:
> > 
>  <snip />
> > 
> > But the actual file has about 100 <economist> elements.
> > I need to write some Perl code to parse this XML file and 
> > write out 100 smaller XML files, each file corresponding to one 
> > <economist> element.
> > 
> > So in my example, I'd write 2 smaller files, one that 
> > looks like this:
>  <snip />
> > 
> > There are some nested elements in the real file, so I think 
> > XML::Simple won't work for this.
> > 
> > Any ideas about how I can do this?  I don't need to do any processing 
> > (at least not now) - just reading and writing smaller chunks.
> > 
> 
> This uses one of my favorite modules, XML::XPath:
> 
> [trwww@waveright trwww]$ perl
> use warnings;
> use strict;
> use XML::XPath;
> use IO::File;
> 
> my($xp) = XML::XPath->new( xml => join('', <DATA>) );
> my($nodeset) = $xp->find(  '/root/economist' );
> 
> my($ext) = 0;
> 
> foreach my $record ( $nodeset->get_nodelist() ) {
>   IO::File->new('> record.'.$ext++)->print($record->toString());
> }
> 
> __DATA__
> <root>
> <economist publications="true" >
>         <name>
>                 <first>John</first>
>                 <last>Doe</last>
>         </name>
>         <keywords>
>                 <keyword>Foo</keyword>
>                 <keyword>Bar</keyword>
>         </keywords>
>         <title>Indian Chief</title>
> </economist>
> 
> <economist publications="true" >
>         <name>
>                 <first>Jane</first>
>                 <last>Smith</last>
>         </name>
>         <keywords>
>                 <keyword>More Foo</keyword>
>                 <keyword>More Bar</keyword>
>         </keywords>
>         <title>President</title>
> </economist>
> </root>
> Ctrl-D
> [trwww@waveright trwww]$ ls -l
> total 24
> drwxr-xr-x    3 trwww    trwww        4096 Aug 17 19:00 apps
> drwx------    3 trwww    trwww        4096 Sep 16 20:49 Desktop
> drwxr-xr-x    3 trwww    trwww        4096 Aug 18 16:50 misc
> drwxrwxr-x    3 trwww    trwww        4096 Sep  6 19:00 public_html
> -rw-rw-r--    1 trwww    trwww         297 Sep 17 22:56 record.0
> -rw-rw-r--    1 trwww    trwww         306 Sep 17 22:56 record.1
> [trwww@waveright trwww]$ cat record.0
> <economist publications="true">
>         <name>
>                 <first>John</first>
>                 <last>Doe</last>
>         </name>
>         <keywords>
>                 <keyword>Foo</keyword>
>                 <keyword>Bar</keyword>
>         </keywords>
>         <title>Indian Chief</title>
> </economist>[trwww@waveright trwww]$ cat record.1
> <economist publications="true">
>         <name>
>                 <first>Jane</first>
>                 <last>Smith</last>
>         </name>
>         <keywords>
>                 <keyword>More Foo</keyword>
>                 <keyword>More Bar</keyword>
>         </keywords>
>         <title>President</title>
> </economist>[trwww@waveright trwww]$
> 
> Todd W.


Thanks!  This works beautifully. 
Now, here are two more things.

Instead of naming the files record.[0..n], I want each 
output file to have the name of the person.  
So these two files would be named Jane.Smith and John.Doe

Also, within each <economist> element, there is now an element 
called <work> that contains other elements.  I need each of these 
<work> elements to be writtten to its own file called lastname_work 
and not in the first output file.

So for this XML file: 

<root>
<economist publications="true" >
        <name>
                <first>John</first>
                <last>Doe</last>
        </name>
        <keywords>
                <keyword>Foo</keyword>
                <keyword>Bar</keyword>
        </keywords>
        <title>Indian Chief</title>
        <work>
             <title>Title 1</title>
             <content>Some Content</content>
        </work>
</economist>

<economist publications="true" >
        <name>
                <first>Jane</first>
                <last>Smith</last>
        </name>
        <keywords>
                <keyword>More Foo</keyword>
                <keyword>More Bar</keyword>
        </keywords>
        <title>President</title>
        <work>
             <title>Title 2</title>
             <content>Some More Content</content>
        </work>
</economist>

So this would produce the same two files your original code produced, 
but named John.Doe and Jane.Smith and also without the <work> element.  
Instead of printing the work element in this file, it should be printed 
in its own file, in this case, called Smith_work and Doe_work.

Thanks again.


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

Date: Thu, 18 Sep 2003 08:41:45 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string to integer
Message-Id: <slrnbmjdgp.ai1.tadmc@magna.augustmail.com>

Mark Fenbers <Mark.Fenbers@noaa.gov> wrote:

> I don't post very often to newsgroups 


Then isn't it possible that there are aspects of Usenet that
you are unaware of?

I post to newsgroups rather often, so I _am_ aware of them.

I thought I'd share what I have learned with you, but you seem
resistant to learning how to get the most out of Usenet...


> because there always has to be some
> condescending know-it-all to chime in his two cents.  


Some folks will be able to forgive you for that, others will
just ignore every post that you make in the future.


> Someone always finds a way
> to be rude...  


Posting MIME is seen as rude on Usenet.

Top-posting is seen as rude on Usenet.

Asking about hex values without even bothering to see if there is a
function named hex() is seen as rude as well.

People that _do_ use newsgroups often will recognize who is
being rude here...


> Tad, your comments were critical, not helpful.  


You needed the hex() function. I told you about the hex() function.
How is that not helpful?

Your posts are being ignored by the people most qualified to answer
your questions, I told you how to avoid being ignored. That seems
"helpful" to me too...


> *sigh*  I guess I
> expected better etiquette from a professional...


You can expect rudeness to be repaid in kind.

If you hope to avoid rudeness, then avoid being rude yourself
in the first place.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 18 Sep 2003 16:16:50 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: timur@tabi.org (Timur Tabi)
Subject: Re: WWW::Mechanize click() returns "Unexpected field value"
Message-Id: <b166d838de23f53cb906517d6115c683@news.teranews.com>

>>>>> "Timur" == Timur Tabi <nospam_timur@tabi.org> writes:

Timur> I read that web page, and I don't think any of those "reasons" apply
Timur> to my re-post.  I believe the reason why my post was ignored was
Timur> because almost no one read it.  It was posted late at night,

Who's "night"?  There are people here that are reading 24x7, in nearly
every timezone.

Timur>  and by
Timur> the next morning, there were so many other posts that mine was
Timur> "crowded out".

Ahh, you've made the "help desk" mistake.  This is not a help desk.
People will answer interesting questions, discuss others, and ignore
others.  It's not up to you to decide someone else's response
schedule, and reposting a question only irritates the locals.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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 5523
***************************************


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