[16850] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4262 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 8 14:10:37 2000

Date: Fri, 8 Sep 2000 11:10:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968436621-v9-i4262@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 8 Sep 2000     Volume: 9 Number: 4262

Today's topics:
        Packet problem <jon@king-fu.freeserve.co.uk>
    Re: Packet problem <jeffp@crusoe.net>
    Re: Passing arrays to a sub routine <jeffp@crusoe.net>
    Re: Passing arrays to a sub routine kelly.carmichael@trx.com
        Qualifications for new Perl programmer????? <gregefalk@cadvision.com>
        Scoping of symbolic references (variables) (Avast)
    Re: Scoping of symbolic references (variables) <sariq@texas.net>
    Re: Scoping of symbolic references (variables) nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 8 Sep 2000 17:22:39 +0100
From: "King Fu" <jon@king-fu.freeserve.co.uk>
Subject: Packet problem
Message-Id: <8pb47n$4qd$1@newsg2.svr.pol.co.uk>

I wish to send some data over a socket but i wish to inlude hex aswell. So
if you sent the string "TEST" followed with teh hex codey "4B" and looked at
the data of the packet sent using a packet sniffer it would look like "54 45
53 54 4B".
But the problem is i dont seem to be able to print 4B properly to the socket
as it gets converted into ascii.
Anyone got any ideas of what i should be doing or am doing wrong? I hope the
above makes sense i know i didnt explain it that well :(
cheers

jon
jon@king-fu.freeserve.co.uk





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

Date: Fri, 8 Sep 2000 12:34:59 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Packet problem
Message-Id: <Pine.GSO.4.21.0009081233040.23350-100000@crusoe.crusoe.net>

On Sep 8, King Fu said:

>But the problem is i dont seem to be able to print 4B properly to the socket
>as it gets converted into ascii.

If your problem is you don't know how to print an ASCII character by hex
value (like printing the character 'a', whose hex value is 61), then do:

  print chr(0x61);  # prints 'a'

or

  print chr(hex('61'));  # prints 'a'

or

  print pack "H2", 61;  # prints 'a'

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Fri, 8 Sep 2000 11:08:37 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Passing arrays to a sub routine
Message-Id: <Pine.GSO.4.21.0009081106590.23350-100000@crusoe.crusoe.net>

On Sep 8, Rich More said:

>In article <8parmg$mi6$1@nnrp1.deja.com>,
>  kelly.carmichael@trx.com wrote:
>>
>> copySrcFiles(\@srcDir,\$srcOutDir);
>> sub copySrcFiles(){}

I'm surprised no one's commented on the fact that there's a prototype
given (albeit too late) and that, if it had been declared previously, it
would cause much more distress, since a function prototyped as () doesn't
take any arguments.

Remove the () from your function definition.  This isn't how you declare
functions in Perl.  The () has an entirely different meaning.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Fri, 08 Sep 2000 15:24:54 GMT
From: kelly.carmichael@trx.com
Subject: Re: Passing arrays to a sub routine
Message-Id: <8pb0bd$sa5$1@nnrp1.deja.com>

In article <7aog1zylr8.fsf@merlin.hyperchip.com>,
  Ala Qumsieh <aqumsieh@hyperchip.com> wrote:
>
> I was missing the small detail of dereferencing, I actually missed
that detail in the "Perl In A Nutshell" book<---that was my FM! :)
Thanks to all for the help and suggestions!!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 08 Sep 2000 09:47:04 -0600
From: Peter Gregefalk <gregefalk@cadvision.com>
Subject: Qualifications for new Perl programmer?????
Message-Id: <39B909F7.F9C1BCC5@cadvision.com>

Hi,

Anybody with experience with hiring Perl programmers or even programmers
with experience of what employers are looking for in a new Perl
programmer?

I would like to find out the most common qualifications looked after in
a Perl programmer in the field of Web applications. I know it's
impossible to generalize everybody's needs into a somewhat short list.
But if there is something that comes to your mind when thinking about
this, please send a respond.

Thank You,
Peter Gregefalk



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

Date: Fri, 08 Sep 2000 15:50:07 GMT
From: avast@hortonsbay.com (Avast)
Subject: Scoping of symbolic references (variables)
Message-Id: <39b9083b.11769635@news.mco.edu>

Am doing a bit of experimenting with symbolic references and have hit
an issue that stumps me.  Hope one you fine folks can offer some
insight here.

#!/usr/local/bin/perl -w
use strict;
no strict 'refs';
while (<DATA>)
{
    chomp (my @list = split /,/);
    foreach my $item (@list)
    {
        if (defined $$item) { $$item++; }
        else { $$item = 0; }
        print "$item = $$item\n"; 
    }
}
__END__
MSH,EVN,PID,NK1,NK1,PV1,GT1,GT1,GT1
MSH,EVN,PID,NK1,NK1,PV1,GT1,GT1,GT1

Output:
MSH = 0
EVN = 0
PID = 0
NK1 = 0
NK1 = 1
PV1 = 0
GT1 = 0
GT1 = 1
GT1 = 2
MSH = 1
EVN = 1
PID = 1
NK1 = 2
NK1 = 3
PV1 = 1
GT1 = 3
GT1 = 4
GT1 = 5

What I expected to happen was for the reference count of each of the
$$item variables (e.g., ${'MSH'}, ${'EVN'}, etc., etc.,) to go
undefined when the current iteration of the foreach loop ends.  If I
change the program to:

#!/usr/local/bin/perl -w
use strict;
no strict 'refs';
while (<DATA>)
{
    chomp (my @list = split /,/);
    foreach my $item (@list) { $$item = 0; }
    foreach my $item (@list)
    {
        print "$item = $$item\n"; 
        $$item++;
    }
}
__END__
MSH,EVN,PID,NK1,NK1,PV1,GT1,GT1,GT1
MSH,EVN,PID,NK1,NK1,PV1,GT1,GT1,GT1

Output
MSH = 0
EVN = 0
PID = 0
NK1 = 0
NK1 = 1
PV1 = 0
GT1 = 0
GT1 = 1
GT1 = 2
MSH = 0
EVN = 0
PID = 0
NK1 = 0
NK1 = 1
PV1 = 0
GT1 = 0
GT1 = 1
GT1 = 2

It works as I expected the first script to work.

I can't find any clear documentation on the scoping of symbolic
references, specifically how to force them out of scope.  Are they
treated as global variables and exist for the duration of the life of
the script?  Again, any insight woould be greatly appreciated.

Thanks!!!!

Avast


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

Date: Fri, 08 Sep 2000 11:22:40 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Scoping of symbolic references (variables)
Message-Id: <39B91250.CAA6E522@texas.net>

Avast wrote:
> 
> Am doing a bit of experimenting with symbolic references and have hit
> an issue that stumps me.  Hope one you fine folks can offer some
> insight here.

<snipped code showing that evil symrefs are global>

> I can't find any clear documentation on the scoping of symbolic
> references, specifically how to force them out of scope.  Are they
> treated as global variables and exist for the duration of the life of
> the script?

Yes.  And you can't local()ize them, either.

> Again, any insight woould be greatly appreciated.

Read:

http://www.plover.com/~mjd/perl/varvarname.html

(Note that there are three parts.  And thanks to mjd.)

- Tom


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

Date: 08 Sep 2000 17:22:39 +0100
From: nobull@mail.com
Subject: Re: Scoping of symbolic references (variables)
Message-Id: <u97l8m3lbk.fsf@wcl-l.bham.ac.uk>

avast@hortonsbay.com (Avast) writes:

> Am doing a bit of experimenting with symbolic references and have hit
> an issue that stumps me.

Symbolic references are by their nature references to package
variables.  Variables accessed by symbolic references have package
scope.

> What I expected to happen was for the reference count of each of the
> $$item variables (e.g., ${'MSH'}, ${'EVN'}, etc., etc.,) to go
> undefined when the current iteration of the foreach loop ends.

${'MSH'} is the same as $MSH.  (Unless there's also a lexical called
$MSH)

Consider the code

{ $MSH = 1 }

Would you expect $MSH to go out of scope at the end of the block?

No.

So don't expect it to do so if you access it via a symbolic ref.

> I can't find any clear documentation on the scoping of symbolic
> references,

You don't mean scoping symbolic references.  You mean scoping the
varialbles referred to by sybolic references.  Like I said they have
to be of package scope.

> specifically how to force them out of scope.

You can't force global varaibles out of scope.  

You probably simply want to avoid symbolic references and use elements
in a lexically scoped hash.  Say $hl7_message{MSH} rather than
${'MSH'}.

>  Are they treated as global variables and exist for the duration of
> the life of the script?

Yes they are package (aka global variables).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4262
**************************************


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