[22871] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5092 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 8 00:05:39 2003

Date: Sat, 7 Jun 2003 21:05:07 -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           Sat, 7 Jun 2003     Volume: 10 Number: 5092

Today's topics:
        an alias for multiple 'use's <blaylock@cs.rochester.edu>
    Re: an alias for multiple 'use's <ndronen@io.frii.com>
    Re: char to number conversion w/ a twist (Tad McClellan)
    Re: Converting numerical character references to Unicod <flavell@mail.cern.ch>
        get pid of system command <ericw@nospam.ku.edu>
    Re: get pid of system command <ericw@nospam.ku.edu>
    Re: move() from File::Copy package fails with cross-dev <eric-amick@comcast.net>
    Re: Perl and Win32 OLE Excel scripting problem/question (Jeff Leary)
    Re: Perl exam - fair or not? (Tad McClellan)
    Re: Perl exam - fair or not? <grazz@pobox.com>
    Re: Perl exam - fair or not? <uri@stemsystems.com>
    Re: Perl exam - fair or not? <robert.j.sipe@boeing.com>
    Re: socket.pm broken ? (getprotobyname does not work) <ndronen@io.frii.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 7 Jun 2003 19:02:07 -0400
From: Nate Blaylock <blaylock@cs.rochester.edu>
Subject: an alias for multiple 'use's
Message-Id: <Pine.LNX.4.44.0306071825450.26376-100000@maputo.cs.rochester.edu>

Hi all,

Is it possible to do this?

In just about every package & program I write, I use a bunch of the same 
stuff, some perl modules and some of my own:

use Carp;
use Storable;
 ...

use MyStuff::Bob;
use MyStuff::Joe;
 ...

I would like to be able to shortcut all of that and do something like use 
a single package which would be equivalent to doing the long version 
above.  E.g.,

use MyStuff::BasicUses;

I tried writing an import sub in MyStuff::BasicUses which makes the uses 
calls above, but that doesn't seem to work.

Is there anything else I can try?

thanks,

nate



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

Date: 08 Jun 2003 03:42:37 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: an alias for multiple 'use's
Message-Id: <3ee2b0ad$0$201$75868355@news.frii.net>

Nate Blaylock <blaylock@cs.rochester.edu> wrote:
NB> Hi all,

NB> Is it possible to do this?

NB> In just about every package & program I write, I use a bunch of the same 
NB> stuff, some perl modules and some of my own:

NB> use Carp;
NB> use Storable;
NB> ...

NB> use MyStuff::Bob;
NB> use MyStuff::Joe;
NB> ...

NB> I would like to be able to shortcut all of that and do something like use 
NB> a single package which would be equivalent to doing the long version 
NB> above.  E.g.,

NB> use MyStuff::BasicUses;

NB> I tried writing an import sub in MyStuff::BasicUses which makes the uses 
NB> calls above, but that doesn't seem to work.

NB> Is there anything else I can try?

	$ cat StdModules
	use Carp;
	1;
	$ perl -wle 'BEGIN { require "StdModules" }; confess()'
	 at -e line 1

Regards,

Nicholas

-- 
"Why shouldn't I top-post?"    http://www.aglami.com/tpfaq.html
"Meanings are another story."  http://www.ifas.org/wa/glossolalia.html


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

Date: Sat, 7 Jun 2003 20:34:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: char to number conversion w/ a twist
Message-Id: <slrnbe54l6.6ko.tadmc@magna.augustmail.com>

MF <mfabache@yahoo.com> wrote:

> Input:
> 32,18,27,172,483.0M,,6.23,,1,3,20.0K,116.0K
> 
> Desired Output:
> 32,18,27,172,483000000,,6.23,,1,3,20000,116000


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

my $in = '32,18,27,172,483.0M,,6.23,,1,3,20.0K,116.0K';
print "$in\n";

$in =~ s{ ([^,]+)  ([MK])  (?=,|$) }
        {
           $2 eq 'K'   ?   $1 * 1_000   :   $1 * 1_000_000;
        }xge;
print "$in\n";
-------------------------


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


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

Date: Sun, 8 Jun 2003 03:51:36 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Converting numerical character references to Unicode
Message-Id: <Pine.LNX.4.53.0306080343590.5788@lxplus086.cern.ch>

On Sat, Jun 7, Arvin Portlock inscribed on the eternal scroll:

> Yup, that works, Thanks! For some reason I didn't think the binmode
> thing was the way to do it in Perl 5.8.

You can put the coding discipline on 'open' if you want, rather than
binmode.  The tutorial goes into detail, as I said.

> I tried a whole variety of things using Unicode::String, too
> numerous to post here. Binmode just seemed so perl 5.6. Now I know.

It's also possible to communicate the required coding to the Perl
implicitly via a locale setting - which has, apparently, come as a
considerable surprise to users of some recent linux distributions -
but I reckon you're better off to understand what you're doing, rather
than waving a dead chicken over it and hoping it'll all come out right
in the end.  I found the tutorial helpful, which was why I commended
it to you.

all the best.


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

Date: Sat, 07 Jun 2003 23:09:24 GMT
From: Eric Wilhelm <ericw@nospam.ku.edu>
Subject: get pid of system command
Message-Id: <pan.2003.06.07.18.06.37.339510.25831@nospam.ku.edu>

When a command is started from the bash shell with "app &", it prints the
job number and pid of the process.  Is there any way to get the pid
number from inside a perl script?  I could call it with system("app &")
and then look in `ps ax -w` for the app name, but it seems like there
must be a better way.

Any suggestions?

Thanks,
Eric


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

Date: Sat, 07 Jun 2003 23:12:53 GMT
From: Eric Wilhelm <ericw@nospam.ku.edu>
Subject: Re: get pid of system command
Message-Id: <pan.2003.06.07.18.10.07.15815.25831@nospam.ku.edu>

On Sat, 07 Jun 2003 18:09:24 -0500, Eric Wilhelm wrote:

> When a command is started from the bash shell with "app &", it prints
> the job number and pid of the process.  Is there any way to get the pid
> number from inside a perl script?  I could call it with system("app &")
> and then look in `ps ax -w` for the app name, but it seems like there
> must be a better way.

And maybe this is the one:
$pid=open(PH, "app &|")

Found this in "perldoc -q external process", but it looks like I've got
some reading still to figure out the why of it all.

--Eric


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

Date: Sat, 07 Jun 2003 23:37:20 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: move() from File::Copy package fails with cross-device link
Message-Id: <09a5evk2vbjrgb0959bks7gldu5rdtu5lf@4ax.com>

On 3 Jun 2003 09:05:20 -0700, carltonbrown@hotmail.com (Carlton Brown)
wrote:

>After further investigation, I am pretty sure I have found a bug in
>File::Copy.  I tested this on 5.005_03 and 5.6.1 and the behavior was
>identical.
>If anyone believes this is not a bug, I am interested in your reason
>for thinking this.
>
>The move() function of File::Copy was designed to encapsulate moving
>files between file systems, and therefore it should never fail with
>the error "Cross-device link."  However, I have found a scenario where
>exactly this situation occurs.
>
>Basically, if the files are on different file systems, and if
>effective UID of the script doesn't have write permissions to the
>source directory, then move() will fail and set $! to an inappropriate
>error message of "cross-device link."

I looked at the code, and what's happening is that you're getting the
error code from the failed rename attempt (which was saved in local
variables) instead of the failed unlink.  I agree that the error code is
misleading.  The fix looks quite simple; you just need to save the error
code from the failed copy/unlink attempt before trying to clean up the
possibly copied file, then restore the code before returning from the
function.

-- 
Eric Amick
Columbia, MD


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

Date: 7 Jun 2003 15:14:53 -0700
From: jeffleary00@hotmail.com (Jeff Leary)
Subject: Re: Perl and Win32 OLE Excel scripting problem/question... simple?
Message-Id: <7dd4facb.0306071414.5acc857d@posting.google.com>

THANKS!

Of course! I can't believe I overlooked that!
I get so used to Perl not really caring too much about the distinction
between nums and strings that I got lazy when it comes to other
languages being so sensitive!

[ snip ]
> 
>     @L = map $_+0, qw(4 2 5 2 3 8 2 8 13 9);
> 

Clever! the "map $_+0" was not something I was aware of. I'll use that
A LOT in the future!

Thanks again!


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

Date: Sat, 7 Jun 2003 17:29:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl exam - fair or not?
Message-Id: <slrnbe4pps.65u.tadmc@magna.augustmail.com>

anon <> wrote:

> A friend of mine took a Perl class in college and was given this exam.


> 5. What special meanings does the caret (^) character have in regular
> expressions? 


>  (b) When it is the first character inside a character class ([]), it
> represents a "not" in the set. 

>  (d) Represents a beginning of line anchor. 


Those are _both_ (kinda) correct.

(beginning of _string_ anchor, not "line")

The answer must be (d) because if the caret is in a char class,
then it is not in a "regular expression", it is in a char class.

The funny characters have different meaning depending on which
language you are parsing at the time.

(the third meaning is "bitwise XOR" if you are currently parsing
 the Perl language.
)


> 17. Which function allows you read a certain byte position within a
> file? (Choose only ONE)
>  (a) tell 
>  (b) find 
>  (c) raccess 
>  (d) seek 


(what is "raccess"?)

None of those read *anything* !

There is no correct answer for the question as asked.


> 19. What is true about the ARGV array? 
>  (a) Identical to the ARGV array in C. 
>  (b) ARGV[0] holds the name of the program. 
>  (c) When no arguments are given to a program, the array evaluates to
> FALSE. 
>  (d) Its array index starts at 1. 


There is no correct answer for that question either.

What it evaluates to depends on what context it is evaluated in.


> 23. What is the return value of a subroutine?  (Choose only ONE)

>  (b) The value of the last _expression evaluated (either scalar or an
> array). 


The test writer seems confused about the distinction between
an "array" and a "list".

Perhaps he/she just hasn't read the Perl FAQ...


> 28. Which are valid methods of turning on call-by-value? 
>  (a) Using the local function. 
>  (b) Using the my function. 
>  (c) Using the values function. 
>  (d) Using the & symbol to call the subroutine. 


There is no correct answer for that question either.

call-by-value is *impossible* in Perl, so you cannot "turn it on",
though you _can_ get the _effect_ of call-by-value by making a copy
and operating only on the copy.


> 35. An anonymous subroutine is created by using the keyword sub and
         ^^^^^^^^^
> prefixing the subroutine name with string "anon_" (true/false). 
                           ^^^^

Anonymous things do not _have_ names.

You don't need to know Perl, or even programming in order to
answer that one correctly.  :-)


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


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

Date: Sun, 08 Jun 2003 00:25:31 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Perl exam - fair or not?
Message-Id: <%nvEa.45453$ca5.21252@nwrdny02.gnilink.net>

anon <> wrote:
>
> 5. What special meanings does the caret (^) character have in regular
>    expressions? 
>  (b) When it is the first character inside a character class ([]), it
>      represents a "not" in the set. 
>  (d) Represents a beginning of line anchor. 

(d) is only true with the /m modifier.  Otherwise "^" matches the 
beginning of the string.

> 6. What is true about POSIX character classes? (Choose only ONE) 
>  (c) You can negate one of the characters in a POSIX character class. 

I suppose this is true, since you can negate any character, but
it's poorly phrased if the instructor was thinking of [:^alnum:]
and a bit of a cheap shot if she meant [^a[:^alnum:]].

Or maybe there's some other interpretation?

> 10. What is true about the m modifier. 
>  (b) Used to control the behavior of the ^ (anchor), $, and \Z 
>      metacharacters. 
>  (d) Used to control the behavior of the ^ (anchor), \A, and \Z
>      metacharacters. 

These are both incorrect; /m doesn't affect \A or \Z.

> 21. What are the differences between subroutines and functions in
>     Perl? 
>  (b) A function is simply a subroutine that happens to have an
>      explicit return value. 

False distinction...  Perl doesn't assign any official meaning to
the term "function", which is used to mean "operator" in some of the
docs and "subroutine" in others.

> 28. Which are valid methods of turning on call-by-value? 
>  (a) Using the local function. 
>  (b) Using the my function. 

Neither of those "turn on" call-by-value, and you can copy
the arguments from @_ without using local() or my().

> 30. Which of the following are true about lexically scoped variables? 
>  (b) Visible from the point of declaration to the end of the innermost
>      enclosing block. 
>  (d) my ($variables) are lexically scoped. 

That ought to be 'enclosing block, file or "eval"', just like it
says in perlfunc.

> 38. What is the following statement? 
> *myalias=*myvar; 
>  (a) a typeglob. 
>  (c) a symbolic reference. 

I don't think I would have called this a symbolic reference.

> 43. In which order does Perl search for a subroutine (method) that
> cannot be found in the current package? (Choose only ONE)
>  (c) @ISA, AUTOLOAD subroutine, UNIVERSAL package 

UNIVERSAL goes before AUTOLOAD().

> 46. What's the difference between static and virtual methods? 
>  (a) Static methods expect a class name as the first argument, and
>      virtual methods expect an object reference as the first argument. 
>  (c) Static methods are used to create a object or act on a group of
>      objects, virtual methods are used to control the way the object's 
>      data

Better to distinguish between "class" methods and "object" or 
"instance" methods.  "virtual" is especially redundant, since 
all method calls are resolved at runtime.

> 49. What is true about the "::" and "->" notations when using
>     polymorphism, dynamic binding and inheritance. 
>  (a) Both are allowed. 
>  (d) -> is more flexible and less problematic than ::. 

Probably "::" should be spelled "indirect object", in order to
distinguish between

    $foo = new Foo::Bar();
    $foo = Foo::Bar->new;

If the question is comparing subroutine calls with method calls

    Foo::Bar::meth($foo);
    $foo->meth();

then the bit about about "::" supporting inheritance and polymorphism
is incorrect.

-- 
Steve


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

Date: Sun, 08 Jun 2003 01:56:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl exam - fair or not?
Message-Id: <x7vfvhuyb3.fsf@mail.sysarch.com>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

  >> 19. What is true about the ARGV array? 
  >> (a) Identical to the ARGV array in C. 
  >> (b) ARGV[0] holds the name of the program. 
  >> (c) When no arguments are given to a program, the array evaluates to
  >> FALSE. 
  >> (d) Its array index starts at 1. 


  TM> There is no correct answer for that question either.

  TM> What it evaluates to depends on what context it is evaluated in.

hmm, an empty array is () in list context and 0 in scalar context. both
are false in my book. but there is not 'false' to evaluate too. (c) is
just worded very poorly. the whole test is a crock like most HR oriented
tests.

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


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

Date: Sun, 8 Jun 2003 01:56:01 GMT
From: "Robert" <robert.j.sipe@boeing.com>
Subject: Re: Perl exam - fair or not?
Message-Id: <HG541D.E9v@news.boeing.com>

A sign of liberal professors needing to impose themselves upon hapless
students.  Let take back our schools!


<anon> wrote in message news:6lj4evo1lk8l782dlgvocoba1pap35i2oj@4ax.com...
> A friend of mine took a Perl class in college and was given this exam.





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

Date: 08 Jun 2003 00:37:41 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: socket.pm broken ? (getprotobyname does not work)
Message-Id: <3ee28554$0$202$75868355@news.frii.net>

peter pilsl <pilsl_usenet@goldfisch.at> wrote:

pp> I've run in quite an irritating problem. On a brand new machine I needed to 
pp> install some perl-applications that returned the error "bad protocol tcp" 
pp> (ie. when trying to create an ldap-object or some think like this).

pp> I now traced the error to the following very simple perlscript:

pp> #!/usr/bin/perl -w
pp> use Socket;
pp> $proto = getprotobyname('tcp');
pp> print $proto?$proto:"failed","\n";

pp> On all machines I maintain, this script returns the value '6'.  On the 
pp> machine in question I get 'failed' as return. 

What does

	$ grep tcp /etc/protocols

return on the machine where getprotobyname() misbehaves?

Regards,

Nicholas

P.S.  Spend an hour or so introducing yourself to strace while you're
at it.  It's a useful tool.

-- 
"Why shouldn't I top-post?"    http://www.aglami.com/tpfaq.html
"Meanings are another story."  http://www.ifas.org/wa/glossolalia.html


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

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


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