[24942] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7192 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 29 18:06:42 2004

Date: Wed, 29 Sep 2004 15:05:11 -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, 29 Sep 2004     Volume: 10 Number: 7192

Today's topics:
    Re: help with eval <tadmc@augustmail.com>
        How can I find out where a subroutine is defined? <stanb@panix.com>
    Re: How to check size of harddisk? <qjason@starhub.net.sg>
    Re: How to check size of harddisk? <qjason@starhub.net.sg>
    Re: How to embed javascript functionality into a Perl C <ceo@nospan.on.net>
        modeling an object many to many relationship with a tra (Jim Thomason)
    Re: modeling an object many to many relationship with a <1usa@llenroc.ude.invalid>
    Re: Newbie: String concatenation limited to 256 charact <Joe.Smith@inwap.com>
    Re: Newbie: String concatenation limited to 256 charact <mritty@gmail.com>
    Re: Odd sort() problem <mritty@gmail.com>
    Re: Odd sort() problem <bigal187@invalid.rx.eastcoasttfc.com>
    Re: Odd sort() problem <1usa@llenroc.ude.invalid>
    Re: Odd sort() problem <mritty@gmail.com>
    Re: Odd sort() problem <someone@example.com>
    Re: parsing XML using a regular expression <dformosa@zeta.org.au>
    Re: Perl vs PHP <bigal187@invalid.rx.eastcoasttfc.com>
        returning a value from a hash using a reference (wana)
    Re: returning a value from a hash using a reference <noreply@gunnar.cc>
        Syntax appears inconsistent - why is this? <ineverreadanythingsenttome@hotmail.com>
    Re: Syntax appears inconsistent - why is this? <1usa@llenroc.ude.invalid>
    Re: Syntax appears inconsistent - why is this? <noreply@gunnar.cc>
    Re: Syntax appears inconsistent - why is this? <mritty@gmail.com>
        Trailing Spaces -- Format Perl (KVN Chary)
    Re: Trailing Spaces -- Format Perl <someone@example.com>
    Re: Write filename w/ scalar and bareword <bigal187@invalid.rx.eastcoasttfc.com>
    Re: Write filename w/ scalar and bareword (mt35)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 29 Sep 2004 14:12:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: help with eval
Message-Id: <slrnclm29j.jpn.tadmc@magna.augustmail.com>

Alex  Lee <simplitia@gmail.com> wrote:

> I am using eval, and perhaps many other people are as well, to
> trap syntax errors - thats the whole point. 


There are 2 forms of eval(), a good one (eval BLOCK) and
a bad one (eval EXPR).

Many other people use "eval BLOCK" for exception handling.

People that use "eval EXPR" for exception handling are the exception.

Why can't you use the "eval BLOCK" form like you are supposed to?


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


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

Date: Wed, 29 Sep 2004 19:48:36 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: How can I find out where a subroutine is defined?
Message-Id: <cjf3ik$ifk$1@reader1.panix.com>

I had a machine crash, and I'm trying to recover from the crash. I't a
FreeBSD machine, so I reinstalled a newer version of the OS, and perl and
perl modules using the ports system.

Among the modules thta this perl script uses are Parse::Lex , and
Parse::FixedLength. When run the scrpt it dies on undefiend subroutine
parse. Now this script runs on other machines with older versions of the
modules, and there is no subroutine parse defined in it.

My current working theory is that the interface to one of the modules I sue
has changed. 

Given that it _does_ work on other machines, how can I find out (on them)
what is actually being called here?



-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin


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

Date: Thu, 30 Sep 2004 03:28:14 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: Re: How to check size of harddisk?
Message-Id: <703ml0do6kb6he5biim9r9n16vbcohmpkk@4ax.com>

Sisyphus <kalinaubears@iinet.net.au> wrote:

>Jason Quek wrote:
>d
>> 
>> The OS is Windows XP Pro. I have an indexing script, which, after it
>> is run, needs to report on how much space is left on the harddisk.
>> 
>
>You can use Win32::AdminMisc for this.
>my($total_drive_space, $available_space_on_this_drive) =
>    Win32::AdminMisc::GetDriveSpace($drive);
>
>Cheers,
>Rob

Hi Rob

Where can I find "Win32::AdminMisc"?

I have looked in the standard distribution and CPAN but cannot seem to
find this moduile.

Regards,




Jason Q.


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

Date: Thu, 30 Sep 2004 03:38:43 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: Re: How to check size of harddisk?
Message-Id: <7h3ml09nps4r3fo1vqkt22vbd4aq9pf70k@4ax.com>

Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote:

>Jason Quek wrote:
>> Hi
>> 
>> How can I use Perl to check the size of the harddisk and the amount of
>> space left?
>> 
>> Any help would be appreciated.
>> 
>> Regards,
>> 
>> 
>> 
>> 
>> Jason Q.
>
>Look at this sub I posted a few weeks ago to get the info from WMI
>
>http://www.google.de/groups?hl=de&lr=&ie=UTF-8&selm=4138a093%240%2414528%24bb690d87%40news.main-rheiner.de
>
>Thomas

Hi Thomas

When I run this subroutine, I get this error:

	Undefined subroutine &main::in called at script.cgi line 19

More specifically, the error occurs on this line:

	my @inst = in($wmi->InstancesOf('Win32_ComputerSystem'));

Am I doing something wrongly?

Regards,




Jason Q.


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

Date: Wed, 29 Sep 2004 19:01:34 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: How to embed javascript functionality into a Perl CGI script?
Message-Id: <iED6d.1529$5b1.35@newssvr17.news.prodigy.com>

Vibhu wrote via top-posting :-( :
>>Vibhu wrote:
>>
>>
>>>I have this fundamental problem where I am trying to generate some
>>>HTML content using Perl CGI script. Currently, my CGI script uses some
>>>variables to calculate and value retrieval stuff and throws that onto
>>>a HTML format. In addition to this, I want to add dynamic capability
>>>to my CGI script.
>>>
>>>For example, I generate a HTML web-page using Perl CGI code. In that
>>>generated page, if I have some checkboxes/radio buttons/select windows
>>>etc, I want to generate some dynamic content if I select one of those
>>>elements. This means as soon as I select an item, one of the perl
>>>functions should be invoked. Similarly, how could I do "onMouseOver",
>>>"onClick" etc kind of stuff with Perl CGI scripts? Please help me.
>>>
>>>Thanks
>>>-Vibhu
>>
> Brendon Caligari <bcaligari@nospam.fireforged.com> wrote in message news:<4159d483$0$94918$bed64819@news.gradwell.net>...
> 
>>CGI scripts are executed at the server side.  And server side code can 
>>only be executed when page in question is requested from the server.  To 
>>achieve what you are after you need code that can execute within the 
>>browser itself...such as JavaScript.
>>
>>B.
 > Brendon,
 >
 > I agree with you. Does it mean we can't do dynamic magic in CGI Perl?
 > If so, how can it happen? I had prior experience with JSP and
 > Javascript. JSP executes on server side and Javascript on the client.
 >
 > What actually happens is when Javascript code is embedded inside a
 > server side script, client side code won't get interpreted by the
 > server. Server executes the server side part of it and evaluates it's
 > values and returns boh HTML and Javascript to the browser(client).
 >
 > Client then displays HTML pages along with values returned by server.
 >
 > I did this in JSP. But haven't ever seen how this can be done in perl.
 > So, I'd appreciate help.
 >
 > Thanks again.
 > -Vibhu
 >

Same as you would output HTML via Perl.  A short contrived example:

#!/usr/bin/perl
$|++;

use strict;
use warnings qw( all );

my $count = 7;

print <<EndHTML;
Content-type: text/html

<html>
<head>
<script language="javascript">
<!--
function button1_onClick() {

    alert( 'I output $count lines in $count font sizes!' );

}
//-->
</script>
</head>
<body bgcolor="white" text="black">
<script language="javascript">
<!--
for (var i=1; i<=$count; i++) {
    document.write( '<font size="+' + i + '">This is dynamic content 
using Perl and JavaScript!</font><br>' );
}
-->
</script>
<form name="frmExample">
    <input type="button" name="button1" value="Click Me!" 
onMouseOver="parent.status = 'You cant do onMouseOvers in Perl!'; return 
true;" onMouseOut="parent.status=''; return true;" 
onClick="button1_onClick();">
<!-- Unless you use PerlScript from ActiveState, but that's not a 
portable solution! -->
</form>
</body>
</html>
EndHTML

__END__

-ceo


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

Date: 29 Sep 2004 12:39:54 -0700
From: thomasoniii@gmail.com (Jim Thomason)
Subject: modeling an object many to many relationship with a transactional bridge table
Message-Id: <5cfdfaf7.0409291139.e7f2bed@posting.google.com>

I'll use the standard example, since it's actually quite literally the
case that I have now. I have students and classes. Students have many
classes, classes have many students. It's in my database in the
standard way, I have a students table and a classes table, and a
student_class_rlt table to join the two of them with my many-to-many.

But, of course, that's only how my data is stored and I really care
about how its accessed, and that's all through objects sitting on top
of a persistence layer.

Ideally, I'd like to be able to access my classes from a student via a
method:

my @classes = $students->classes;

And I can do that by having the persistence layer map the
student_class_rlt table to a nonsense class ("StudentClassRLT") and
then populating those objects Class attribute and returning it in
their place. Standard stuff.

The issue, as always, is that my join table contains additional
information, start_date and end_date, for instance (when the student
entered and exited that class), so I can't simply throw away that
middle object.

The solution I came up with is to subclass the Classroom class and
wire it up to both the classes and the student_class_rlt table. Then
the ->classes method returns these newly subclassed objects that are
full fledged classrooms with some additional attributes (the user id,
the start date, the end date).

I really like this approach since it encapsulates everything nicely.

my @classes = $student->classes;

foreach my $class (@classes) {
   print $class->name, "\n";
   print $class->start_date, "\n";
   print $class->end_date, "\n";
};

Then I hit a snag - going the other way from classes to students. I
could just subclass students the same way, but then I ended up
duplicating my definition to interface with the student_class_rlt
table into my Student subclass and my Class subclass. Very very bad.

And that's where I stand.

My first question is, does this approach of subclassing on each side
sound like a reasonable one to take, or is there some potential gotcha
that I'm not thinking of?

Secondly (and more important), what would be a good place to stick the
definition of the bridge table?

I certainly don't want to duplicate it in each class, so that's out.

I could stick it into a side class and have them inherit from that as
well as my root object (no, I don't want to hear about the fragile
base class problem), but then I'm introducing multiple inheritance
which I've so far kept out of the system and would like to keep out.

I could stick it in an external class that just has the data for the
table def, and then have the subclasses pull it in from there, but
that module doesn't really exist as anything on its own.

I could stick the table definition into a configuration file. This
seems like the best approach to me, but I'd need to come up with a
place to store it. It also introduces the concept of storing table
information in two different places (either within a class or within a
configuration file), which I don't like; so I may end up re-working my
existing classes to stick their table definitions into configuration
files as well. I've all but talked myself into taking this approach.

Thoughts?

-Jim.....


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

Date: 29 Sep 2004 19:50:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: modeling an object many to many relationship with a transactional bridge table
Message-Id: <Xns9573A13463A86asu1cornelledu@132.236.56.8>

thomasoniii@gmail.com (Jim Thomason) wrote in 
news:5cfdfaf7.0409291139.e7f2bed@posting.google.com:

> I'll use the standard example, since it's actually quite literally the
> case that I have now. I have students and classes. Students have many
> classes, classes have many students. It's in my database in the
> standard way, I have a students table and a classes table, and a
> student_class_rlt table to join the two of them with my many-to-many.
> 
> But, of course, that's only how my data is stored and I really care
> about how its accessed, and that's all through objects sitting on top
> of a persistence layer.

I am really fond of Class::DBI

http://www.class-dbi.com/cgi-bin/wiki/index.cgi?ComplexManyToMany

might help.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 18:40:53 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Newbie: String concatenation limited to 256 characters?
Message-Id: <VkD6d.72663$wV.70938@attbi_s54>

Piet wrote:
> In the code, the expression
> $oldstring = $oldstring.$newstring
> occurs very often.
> Frequently, the strings get longer than 256 characters. At this point,
> the string concatenation refuses to add anything to $oldstring.

That's a bunch of baloney.  Perl has no problem with large strings.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\jms>perl -le "for($_='a';;$_=$_.$_){print length}"
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
 ...
		-Joe


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

Date: Wed, 29 Sep 2004 19:13:36 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Newbie: String concatenation limited to 256 characters?
Message-Id: <APD6d.2725$va.677@trndny03>

"Piet" <pit.grinja@gmx.de> wrote in message
news:39cbe663.0409290925.2e735196@posting.google.com...
> Hello,
> I have written a small script that parses an (ugly) HTML file line by
> line and converts the relevant information to CSV. During parsing, I
> heavily use string concatenation to glue together parts of text that
> belong together (but might be separated in the original file by tags
> or newlines). In the code, the expression
> $oldstring = $oldstring.$newstring
> occurs very often.
> Frequently, the strings get longer than 256 characters. At this point,
> the string concatenation refuses to add anything to $oldstring. How is
> it possible to avoid that?
> Thanks in advance for answers on  a (maybe very newbish) question
> Piet

You've misdiagnosed your problem.  Perl is very capable of dealing with
arbitrarily long strings.  Therefore, the strings are being cut off by
something else.  My guess would be a fixed length database field that
you might be storing them in.   Since you didn't provide any code, we
have no way of pointing to you to what your actual problem is.

Paul Lalli




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

Date: Wed, 29 Sep 2004 19:10:42 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Odd sort() problem
Message-Id: <SMD6d.2724$va.1263@trndny03>

"187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in message
news:2s0bj9F1f8ihqU1@uni-berlin.de...
> A. Sinan Unur wrote:
> > "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in
> > news:2s07v9F1fvtn5U1 @uni-berlin.de:
> >
> >>    C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp
lc($b)
> >>            } split(/;/, $ENV {'PATH'})), qq{\n};"
> >
> > I like one liners but I avoid them precisely for this type of
problem:
> > lc{$a} should be lc($a) or just lc $a.
>
> But what I really don't understand is why it doesn't result in a
compile
> error? lc{$a}, one would think, is not a valid statement.

The warning below answers this question.

> I admit should I have used -w in there:
>
>    Odd number of elements in anonymous hash at -e line 1.
>    Odd number of elements in anonymous hash at -e line 1.
>    Odd number of elements in anonymous hash at -e line 1.
>    [......]
>

You're passing to the lc() function an anonymous hash.  That anonymous
hash is poorly constructed, containing an odd number of elements.  So it
is not invalid syntax, it's just not at all what you meant.

Paul Lalli





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

Date: Wed, 29 Sep 2004 12:30:31 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: Odd sort() problem
Message-Id: <2s0gs2F1fpl8iU1@uni-berlin.de>

Paul Lalli wrote:
> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in message
> news:2s0bj9F1f8ihqU1@uni-berlin.de...
>> A. Sinan Unur wrote:
>>> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in
>>> news:2s07v9F1fvtn5U1 @uni-berlin.de:
>>>
>>>>    C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp
>>>>            lc($b) } split(/;/, $ENV {'PATH'})), qq{\n};"
>>>
>>> I like one liners but I avoid them precisely for this type of
>>> problem: lc{$a} should be lc($a) or just lc $a.
>>
>> But what I really don't understand is why it doesn't result in a
>> compile error? lc{$a}, one would think, is not a valid statement.
>
> The warning below answers this question.

But shouldn't it be complaining either that lc{ } is an undefined hash
or lc being a bareword?

Even if I add 'use strict;' before the print statement  (or -Mstrict).

>
>> I admit should I have used -w in there:
>>
>>    Odd number of elements in anonymous hash at -e line 1.
>>    Odd number of elements in anonymous hash at -e line 1.
>>    Odd number of elements in anonymous hash at -e line 1.
>>    [......]
>>
>
> You're passing to the lc() function an anonymous hash.  That anonymous
> hash is poorly constructed, containing an odd number of elements.  So
> it is not invalid syntax, it's just not at all what you meant.

But should it not interpret lc{} as a bareword hash, and therefore issue
an error about bareword? I'm askign in case this is actually a bug.




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

Date: 29 Sep 2004 19:39:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Odd sort() problem
Message-Id: <Xns95739F4EA4E3Fasu1cornelledu@132.236.56.8>

"187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in news:2s0gs2F1fpl8iU1
@uni-berlin.de:

> But shouldn't it be complaining either that lc{ } is an undefined hash
> or lc being a bareword?

lc is a builtin.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 20:19:43 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Odd sort() problem
Message-Id: <zNE6d.17368$M45.9624@trndny09>

"187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> Paul Lalli wrote:
> > "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> >> A. Sinan Unur wrote:
> >>> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> >>
> >> But what I really don't understand is why it doesn't result in a
> >> compile error? lc{$a}, one would think, is not a valid statement.
> >
> > The warning below answers this question.
>
> But shouldn't it be complaining either that lc{ } is an undefined hash
> or lc being a bareword?

Of course not.  lc is a built in function.  it's taking whatever comes
after "lc" as the parameter you're passing to lc. In this case, what
follows is an anonymous hash, signified by the { }

> Even if I add 'use strict;' before the print statement  (or -Mstrict).
>
> >
> > You're passing to the lc() function an anonymous hash.  That
anonymous
> > hash is poorly constructed, containing an odd number of elements.
So
> > it is not invalid syntax, it's just not at all what you meant.
>
> But should it not interpret lc{} as a bareword hash, and therefore
issue
> an error about bareword? I'm askign in case this is actually a bug.

No.  It's not a bug.  It's a problem with your belief that { } are used
only to get at an elment of an existing hash.  What you did was
equivalent to this:
$ref = {$a};  #assign a poorly-constructed hashref to $ref;
lc $ref;  #pass that hash reference as a parameter to the lc function.

Paul Lalli




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

Date: Wed, 29 Sep 2004 21:23:47 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Odd sort() problem
Message-Id: <DJF6d.2511$eq.1514@edtnps84>

187 wrote:
> I friend of mine recently accessed me for a little one liner to nicely
> display all the paths in the $PATH vartiable on his NT 5.1 (aka XP Pro)
> machine: (sorry for word wrap)
> 
>    C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
>            split(/;/, $ENV {'PATH'})), qq{\n};"
> 
> [snip]
> 
> I get the same sort of oddness on my Linux machine as well:
> 
>    $ perl -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
>         split(/:/, $ENV{"PATH"})), qq{\n};'
> 
> [snip]
> 
> Both Perl's are 5.6.1, though my Linux also has 5.8.2 which does
> similar, though different order:
> 
>    $ perl5.8.2 -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
>         split(/:/, $ENV{"PATH"})), qq{\n};'
> 
> [snip]
> 
> What is going on here? Why is sort doing this? I've used sort(), map(),
> and grep() in cascaded form like this before without this problem;
> split() returns an array, which get sucked into sort(), who spits it
> back out to join(), does it not?

As others have pointed out the problem is with the anonymous hash in "lc{$a}" 
however if you want to make this more portable and remove all those quotes and 
braces and parentheses:

perl -e 'use Env q/@PATH/; print $/, map $_ . $/, sort { lc $a cmp lc $b } @PATH'


John
-- 
use Perl;
program
fulfillment


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

Date: 30 Sep 2004 07:21:59 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: parsing XML using a regular expression
Message-Id: <m3d604db48.fsf@dformosa.zeta.org.au>

"Leif Wessman" <leifwessman@hotmail.com> writes:

[...]

> Now, does anyone else have any suggestions for me? I would like to
> parse a simple XML file as stated in my first posting. I would not like
> to use an XML-parser.

1 Buy a book on compiler/parser theory, read it and roll your own
recursive decent parser.

2. Use the parser modules (such as Parse::RecDescent or Parse::Yapp)

3. Wait untill perl6 is released and use rules.


-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: Wed, 29 Sep 2004 11:22:35 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: Perl vs PHP
Message-Id: <2s0csbF1ftnmkU1@uni-berlin.de>

Jim Keenan wrote:
> ? the Platypus {aka David Formosa} wrote:
>> "Jürgen Exner" <jurgenex@hotmail.com> writes:
>>
>> [...]
>>
>>
>>> How do you call the opposite of a tautology (i.e always false)?
>>
>>
>> A contradiction.
>>
>
> Oh, no!  The thread that wouldn't die!  Didn't we drive a stake
> through its heart?

mmmmmmm, steak.....




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

Date: 29 Sep 2004 12:54:55 -0700
From: ioneabu@yahoo.com (wana)
Subject: returning a value from a hash using a reference
Message-Id: <bf0b47ca.0409291154.7265dc49@posting.google.com>

I know I must be doing something stupid here.  I want to return a
value out of a hash using a reference.  To be specific:
$session{_session_id} is the hash value I need to get at.  Just to
make things interesting, I named my scalar which refers to %session
with the same name: $session = \%session

I know I could use -> notation, but I thought this would work:

$%$session{_session_id}

or

$$session{_session_id}

or some other variation using appropriate parentheses.

Is it possible to dereference this reference in this way to get at the
value?


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

Date: Wed, 29 Sep 2004 22:05:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: returning a value from a hash using a reference
Message-Id: <2s0ituF1ddogjU1@uni-berlin.de>

wana wrote:
> I know I must be doing something stupid here.  I want to return a
> value out of a hash using a reference.  To be specific:
> $session{_session_id} is the hash value I need to get at.  Just to
> make things interesting, I named my scalar which refers to %session
> with the same name: $session = \%session
> 
> I know I could use -> notation, but I thought this would work:
> 
> $%$session{_session_id}
> 
> or
> 
> $$session{_session_id}
> 
> or some other variation using appropriate parentheses.

     my %session = (session_id => 123);
     my $session = \%session;

# Accessing the hash value directly:
     print $session{session_id}, "\n";

# Dereferencing the hash reference:
     print ${$session}{session_id}, "\n";
     # or
     print $session->{session_id}, "\n";

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


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

Date: Wed, 29 Sep 2004 19:48:04 GMT
From: "David Filmer" <ineverreadanythingsenttome@hotmail.com>
Subject: Syntax appears inconsistent - why is this?
Message-Id: <UjE6d.138341$D%.46143@attbi_s51>

I can define a hash thusly (this works):

my %food_price = ( 'Hotdog' => 1.00, 'Popsicle' => 0.50 );

Or, similarly:

my %food = ('H' => {label => 'Hotdog ',  price => 1.00 },
                      'P' => {label => 'Popsicle',  price => 0.50 });

But the syntax seems inconsistent to me. I would expect to use curlys to 
enclose %food (not parens). I associate curlys with hashes. Is there some 
rationale behind the fact that Perl uses parens to populate a hash in this 
way? Just curious.

curlys = { }, parens = ( )




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

Date: 29 Sep 2004 19:53:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <Xns9573A1AC53C5Basu1cornelledu@132.236.56.8>

"David Filmer" <ineverreadanythingsenttome@hotmail.com> wrote in
news:UjE6d.138341$D%.46143@attbi_s51: 

> I can define a hash thusly (this works):
> 
> my %food_price = ( 'Hotdog' => 1.00, 'Popsicle' => 0.50 );
> 
> Or, similarly:
> 
> my %food = ('H' => {label => 'Hotdog ',  price => 1.00 },
>                       'P' => {label => 'Popsicle',  price => 0.50 });
> 
> But the syntax seems inconsistent to me. I would expect to use curlys
> to enclose %food (not parens). I associate curlys with hashes. Is
> there some rationale behind the fact that Perl uses parens to populate
> a hash in this way? Just curious.

I am curious too. Did you even bother to read any part of the 
documentation?

{label => 'Hotdog ',  price => 1.00 } is a reference to an anonymous 
hash, not a hash itself.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 21:54:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <2s0i7rF1fnl4aU1@uni-berlin.de>

David Filmer wrote:
> I can define a hash thusly (this works):
> 
> my %food_price = ( 'Hotdog' => 1.00, 'Popsicle' => 0.50 );
> 
> Or, similarly:
> 
> my %food = ('H' => {label => 'Hotdog ',  price => 1.00 },
>                       'P' => {label => 'Popsicle',  price => 0.50 });
> 
> But the syntax seems inconsistent to me. I would expect to use curlys
> to enclose %food (not parens). I associate curlys with hashes.

Then stop doing so, and start associating them with hash references 
instead. :)

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


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

Date: Wed, 29 Sep 2004 20:22:14 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <WPE6d.25516$Wa7.2036@trndny06>

"David Filmer" <ineverreadanythingsenttome@hotmail.com> wrote in message
news:UjE6d.138341$D%.46143@attbi_s51...
> I can define a hash thusly (this works):
>
> my %food_price = ( 'Hotdog' => 1.00, 'Popsicle' => 0.50 );
>
> Or, similarly:
>
> my %food = ('H' => {label => 'Hotdog ',  price => 1.00 },
>                       'P' => {label => 'Popsicle',  price => 0.50 });
>
> But the syntax seems inconsistent to me. I would expect to use curlys
to
> enclose %food (not parens). I associate curlys with hashes.

Your association is incorrect.
( ) are used to create arrays and hashes.
{ } are used to create hash references
[ ] are used to create array references

> Is there some
> rationale behind the fact that Perl uses parens to populate a hash in
this
> way? Just curious.

Because Perl always uses parens to populate a hash, and there's nothing
in your example that suggests the need for a special case.

Paul Lalli





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

Date: 29 Sep 2004 13:13:15 -0700
From: kvnchary@yahoo.com (KVN Chary)
Subject: Trailing Spaces -- Format Perl
Message-Id: <b6ec1ff3.0409291213.33436b41@posting.google.com>

Hello,

my $var1 = "temp";
my $var2 = "123";
my $space = " ";

format STDOUT =
@<<<<<<<<< @<<< @<<<<<<<<<<<<<<<<<<<<<<<<<
$var1,$var2,$space
 .

I need to put 26 spaces at the end of line. But this code doesn't work?
How can I do this using FORMAT Perl Command?

Thanks
KVN


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

Date: Wed, 29 Sep 2004 21:59:56 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Trailing Spaces -- Format Perl
Message-Id: <wfG6d.2517$eq.262@edtnps84>

KVN Chary wrote:
> 
> my $var1 = "temp";
> my $var2 = "123";
> my $space = " ";
> 
> format STDOUT =
> @<<<<<<<<< @<<< @<<<<<<<<<<<<<<<<<<<<<<<<<
> $var1,$var2,$space
> .
> 
> I need to put 26 spaces at the end of line. But this code doesn't work?
> How can I do this using FORMAT Perl Command?

Are you sure that you need to use format?  :-)

formline '@<<<<<<<<< @<<< @<<<<<<<<<<<<<<<<<<<<<<<<<', $var1, $var2, $space;

print STDOUT pack 'A42', $^A;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 29 Sep 2004 11:31:36 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <2s0dd8F1gc7dlU1@uni-berlin.de>

A. Sinan Unur wrote:
> mt35@linuxmail.org (mt35) wrote in news:2763816a.0409290416.1ddc5229
> @posting.google.com:
>
>> I'm trying to write a file name using a predefined scalar (my $date =
>> `date "+%m%d%Y"`) and a bareword (snort.tar). Here's the code:
>>
>>
>> #----------Start Code Block------------
>> #!/usr/bin/perl
>>
>> use strict;
>> use Archive::Tar;
>>
>> my $tar = Archive::Tar->new;
>>
>> my $date = `date "+%m%d%Y"`;
>
> Arrrgh! Why???
>
> To solve your immediate problem, add a
>
> chomp $date;
>
> after this.
>

Of just:

   chomp(my $date = `date "+%m%d%Y"`);

:)
That is, if you want ot use that approuch of using the "date" command,
which is rather limiting for portability. Your Perl-only method is much
more logical and portable. Even more the suggestion to use POSIX.




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

Date: 29 Sep 2004 13:56:40 -0700
From: mt35@linuxmail.org (mt35)
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <2763816a.0409291256.31b805f6@posting.google.com>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message news:<Xns9573594CF34A5asu1cornelledu@132.236.56.8>...
> mt35@linuxmail.org (mt35) wrote in news:2763816a.0409290416.1ddc5229
> @posting.google.com:
> 
> > I'm trying to write a file name using a predefined scalar (my $date =
> > `date "+%m%d%Y"`) and a bareword (snort.tar). Here's the code:
> > 
> > 
> > #----------Start Code Block------------
> > #!/usr/bin/perl
> > 
> > use strict;
> > use Archive::Tar;
> > 
> > my $tar = Archive::Tar->new;
> > 
> > my $date = `date "+%m%d%Y"`;
> 
> Arrrgh! Why???
> 
> To solve your immediate problem, add a 
> 
> chomp $date;

This was the problem...Is my newness to perl painfully obvious yet? ;)

> after this.
>  
> > chdir "/home/user/perl" or die "$!";
> > 
> > my @tarlst = ("test0", "test1");
> > 
> > $tar->add_files(@tarlst);
> > $tar->write ("$date test.tar");
> > #--------End Code Block--------------
> > 
> > However the file written is: 09292004?.snort.tar.gz
> 
> That is impossible. You have not run the code you posted. There is no 
> mention of 'snort' anywhere between the 'Start Code Block' and 'End Code 
> Block' markers. Make sure to post the actual code you run.

My mistake, I'll triple check next time.

> > My question is why is the question mark being written?...If I add a
> > "print $date" it comes out fine.
> 
> Define fine. Is it 'fine' that a newline is written even though you have 
> not specified it?

I see your point, I didn't even reconize that was occuring.

> There is no need to spawn an extra process to do something as simple as 
> this.
> 
> sub filename_prefix_generator {
>     my ($sec, $min, $hour, $mday, $mon, $year, undef, undef, undef) =
>         localtime time;
>     sprintf '%2.2d%2.2d%4.4d_%2.2d%2.2d%2.2d', 
>         $mon+1, $mday, $year, $hour, $min, $sec;
> }
> 
> or, look into POSIX::strftime.

That *is* much better...I'll use this instead, along with Tore's suggestions.

Thanks for the help!


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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