[23298] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5518 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 17 18:10:34 2003

Date: Wed, 17 Sep 2003 15:10:12 -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           Wed, 17 Sep 2003     Volume: 10 Number: 5518

Today's topics:
    Re: Quoting "$vars" and open() <ak+usenet@freeshell.org>
    Re: Quoting "$vars" and open() (Tad McClellan)
    Re: Quoting "$vars" and open() <tassilo.parseval@rwth-aachen.de>
    Re: Quoting "$vars" and open() <noreply@gunnar.cc>
        Regex to detect patterns that do not start with // or < (Mike Grandmasion)
    Re: Regex to detect patterns that do not start with //  (Tad McClellan)
    Re: Regex to detect patterns that do not start with //  <abigail@abigail.nl>
        Splitting up an XML File (JAG)
    Re: Splitting up an XML File (Tad McClellan)
    Re: Standards in Artificial Intelligence <nospam@plea.se>
        tied multi dimensional hashes <tom@nosleep.net>
        using GUIs <mail@annuna.com>
    Re: WWW::Mechanize click() returns "Unexpected field va (Timur Tabi)
    Re: WWW::Mechanize click() returns "Unexpected field va (Timur Tabi)
        XML ( WML in particular) <b.dara@tester.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 17 Sep 2003 15:38:53 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Quoting "$vars" and open()
Message-Id: <slrnbmh00a.cru.ak+usenet@vinland.freeshell.org>

In article <slrnbmgsr9.7o0.tadmc@magna.augustmail.com>, Tad McClellan wrote:
> Andreas Kahari <ak+usenet@freeshell.org> wrote:
>> In article <cb9c7b76.0309170556.5bac0a80@posting.google.com>,
>> Chris Marshall wrote:
>>> I know its wrong to quote "$vars" - but is there an easy way around it
>>> when using open() and your filename is in a $var ?
>> 
>> I wouldn't say it's "wrong", 
> 
> If you are going to contradict a Perl FAQ, a little bit of your
> rationale would be appreciated.

Good evening to you too.

> It may aid in improving the answer given in the FAQ.
> 
> How can stringifying a reference be "not wrong"?

A reference?  I tought we were talking about a scalar containing
a filename?

>> open(DATA, ">" . $var) or die;	# Writing
> 
> This is not related to the current discussion.

Hmm...  I must have misread the question.  How do you interpret
the question?

> We are not saying that
>    ">$var"
> is wrong, we are saying that
>    "$var"
> is wrong.

Which is correct in a general way, but we're discussing it in
the context of the open() command.


Cheers,
Andreas

-- 
Andreas Kähäri


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

Date: Wed, 17 Sep 2003 12:29:02 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quoting "$vars" and open()
Message-Id: <slrnbmh6eu.82o.tadmc@magna.augustmail.com>

Andreas Kahari <ak+usenet@freeshell.org> wrote:
> In article <slrnbmgsr9.7o0.tadmc@magna.augustmail.com>, Tad McClellan wrote:

>> If you are going to contradict a Perl FAQ, a little bit of your
>> rationale would be appreciated.

>> How can stringifying a reference be "not wrong"?
> 
> A reference?  


We are discussing this Perl FAQ:

   perldoc -q vars

       What's wrong with always quoting "$vars"?


"What's wrong" according the FAQ answer is the danger of
stringifying a reference.


> I tought we were talking about a scalar containing
> a filename?


I thought we were talking about useless uses of double quotes,
without regard to what the variable's value is, nor where
the variable is used.

You _never_ need

   "$vars"

because

  $vars

will always work in its place.


>>> open(DATA, ">" . $var) or die;	# Writing
>> 
>> This is not related to the current discussion.
> 
> Hmm...  I must have misread the question.  How do you interpret
> the question?


I thought he was asking about the Perl FAQ above.


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


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

Date: 17 Sep 2003 17:56:37 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Quoting "$vars" and open()
Message-Id: <bka78l$nf9$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tad McClellan:

> I thought we were talking about useless uses of double quotes,
> without regard to what the variable's value is, nor where
> the variable is used.
> 
> You _never_ need
> 
>    "$vars"
> 
> because
> 
>   $vars
> 
> will always work in its place.

It should, and actually will for all Perl-builtins. Yet there is a
difference on the inside between these two (which makes your points even
more valid):

    ethan@ethan:~$ perl -MDevel::Peek
    $a = 1;
    Dump($a);
    Dump("$a");
    __END__
    SV = IV(0x812b084) at 0x8128ab0
      REFCNT = 1
      FLAGS = (IOK,pIOK)
      IV = 1
    SV = PV(0x811e638) at 0x8128ac8
      REFCNT = 1
      FLAGS = (PADTMP,POK,pPOK)
      PV = 0x8123078 "1"\0
      CUR = 1
      LEN = 2

The stringification will upgrade the scalar value (well, not really
upgrading - the IV part is lost; there are also cases possible where
both PV and IV exist). So

    $a = 1;
    $b = "$a";

is the equivalent to the other direction as in

    $a = "1";
    $b = $a + 0;

To make people stop using these casts in cases where they are pointless,
it might be worth to remark that a stringification can make a scalar use
more memory and thus reduce the performance slightly:

    ethan@ethan:~$ perl -MDevel::Size=size
    print size(1), "\n";
    print size("1"), "\n";
    __END__
    16
    26

When doing these conversions in a very unclever way, as in

    $a = $b = $c = 1;
    @a = ("$a", "$b", "$c");
    my $sum;
    $sum += $_ for @a;

which means: IV -> PV -> IV, this has runtime-costs since these casts
naturally come at some computational costs that could easily be avoided.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 17 Sep 2003 21:40:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Quoting "$vars" and open()
Message-Id: <bkadm4$r5f9m$1@ID-184292.news.uni-berlin.de>

Gunnar Hjalmarsson wrote:
> Andreas Kahari wrote:
> 
>> open(DATA, ">" . $var) or die;    # Writing
> 
> If you are writing portable code (for Perl < 5.6.0), you can't
> avoid it when including MODE, so the latter needs to be written:
> 
>     open(DATA, "> $var") or die;

Hmm.. I'd better correct myself before somebody else does. ;-)

Both those open() statements specify just two arguments, so they work
in Perl versions before 5.6.0. What require Perl 5.6.0 (or later)
are open() statements with three or more arguments, such as:

     open(DATA, ">", $var) or die;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 17 Sep 2003 09:22:30 -0700
From: surfer97301@yahoo.com (Mike Grandmasion)
Subject: Regex to detect patterns that do not start with // or <!--
Message-Id: <75821f06.0309170822.18e25b5a@posting.google.com>

Hi,

I am trying to write a pattern which will give me all matches in java
files for strings that contain the word "the " but do not start with
//, <!--.

This is my pattern so far,

grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
'out.print.*?[^\<][^!][^-][^-].*?the'

It sort of works but I was wondering if anyone has suggestions on how
to improve it.

Thanks for any pointers,

Mike


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

Date: Wed, 17 Sep 2003 12:33:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex to detect patterns that do not start with // or <!--
Message-Id: <slrnbmh6n1.82o.tadmc@magna.augustmail.com>

Mike Grandmasion <surfer97301@yahoo.com> wrote:

> if anyone has suggestions on how
> to improve it.


Rewrite it in Perl.


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


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

Date: 17 Sep 2003 18:55:10 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regex to detect patterns that do not start with // or <!--
Message-Id: <slrnbmhbgd.dkd.abigail@alexandra.abigail.nl>

Mike Grandmasion (surfer97301@yahoo.com) wrote on MMMDCLXIX September
MCMXCIII in <URL:news:75821f06.0309170822.18e25b5a@posting.google.com>:
--  Hi,
--  
--  I am trying to write a pattern which will give me all matches in java
--  files for strings that contain the word "the " but do not start with
--  //, <!--.

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

--  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.

--  It sort of works but I was wondering if anyone has suggestions on how
--  to improve it.

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


Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: 17 Sep 2003 11:09:38 -0700
From: jeffg@programmer.net (JAG)
Subject: Splitting up an XML File
Message-Id: <6b40b6b9.0309171009.20d66b6a@posting.google.com>

I have an XML file that looks like this:

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

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:
<economist publications="true" >
        <name>
                <first>John</first>
                <last>Doe</last>
        </name>
        <keywords>
                <keyword>Foo</keyword>
                <keyword>Bar</keyword>
        </keywords>
        <title>Indian Chief</title>
</economist>

and one that looks like this:
<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>

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.

Thanks!


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

Date: Wed, 17 Sep 2003 14:15:57 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Splitting up an XML File
Message-Id: <slrnbmhcnd.89l.tadmc@magna.augustmail.com>

JAG <jeffg@programmer.net> wrote:

> 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.


> There are some nested elements in the real file,


I will assume that <economist> is NOT nested, and that the
start/end tags are on lines by themselves.


> Any ideas about how I can do this?


   # strip non-<economist> stuff at top of file
   $/ = "<economist>\n";
   while ( <> ) {      # read one <economist> element per loop iteration
      # open file, output $_ to file, close file.
   }


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


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

Date: 17 Sep 2003 18:24:50 +0200
From: Matthias <nospam@plea.se>
Subject: Re: Standards in Artificial Intelligence
Message-Id: <36w4qzbjsbx.fsf@chagall.ti.uni-mannheim.de>

uj797@victoria.tc.ca (Arthur T. Murray) writes:

> A webpage of proposed Standards in Artificial Intelligence is at 
> http://mentifex.virtualentity.com/standard.html -- updated today.

How about using a mailing list where everyone interested in your
website can subscribe and is informed about your frequent updates?

If everybody posted their update notifications through usenet the news
servers would immediately break down from overload.  So please be
polite and use the appropriate channels to communicate with the
readers of your website.



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

Date: Wed, 17 Sep 2003 08:48:17 -0700
From: "Tom" <tom@nosleep.net>
Subject: tied multi dimensional hashes
Message-Id: <3f688199$1@nntp0.pdx.net>

Can't it be done or what?
I need the quickest and easiest way to accomplish this and so far, nothing
has worked.
Please share a solution, otherwise I'm stuck with incredibly large, but flat
records.
Thanks,
Tom




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

Date: Wed, 17 Sep 2003 19:17:14 GMT
From: Joe Creaney <mail@annuna.com>
Subject: using GUIs
Message-Id: <_q2ab.6618$UN4.2011@newsread3.news.pas.earthlink.net>

I have written some simple GUI.  What I would like to know is how to get 
output in a GUI either text or graphical.



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

Date: 17 Sep 2003 14:51:52 -0700
From: nospam_timur@tabi.org (Timur Tabi)
Subject: Re: WWW::Mechanize click() returns "Unexpected field value"
Message-Id: <53bb806a.0309171351.44b4ee42@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbmgtp6.7o0.tadmc@magna.augustmail.com>...

> What did your Perl friend say when you asked him about it?

He said that it works for him and he has no idea why it doesn't work
for me.  He also could not tell me how to debug it.


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

Date: 17 Sep 2003 14:54:59 -0700
From: nospam_timur@tabi.org (Timur Tabi)
Subject: Re: WWW::Mechanize click() returns "Unexpected field value"
Message-Id: <53bb806a.0309171354.29310533@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbmgtmi.7o0.tadmc@magna.augustmail.com>...

> Are you going to post this same question every 3 days?
> 
>       http://www.plover.com/~mjd/perl/Questions.html

I read that web page, and I don't think any of those "reasons" apply
to my re-post.  I believe the reason why my post was ignored was
because almost no one read it.  It was posted late at night, and by
the next morning, there were so many other posts that mine was
"crowded out".

I think I put quite a bit of detail in my post, and it should be
obvious that I'm not a lazy individual who wants someone else to do
all the work for me.  I'm willing to debug the problem myself, but I
don't know how.


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

Date: Wed, 17 Sep 2003 21:59:02 +0100
From: "Brian" <b.dara@tester.com>
Subject: XML ( WML in particular)
Message-Id: <xW3ab.1961$DM5.18462@newsfep4-glfd.server.ntli.net>

  Hi,

I have a script that generates some WML, and I would like this to be written
to a file using the UTF-8 characterset. Currently it is just written
normally , with the affect that my phone wont recognise it.

How is this done in Perl?

Thanks




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

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


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