[8628] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2245 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 3 21:07:41 1998

Date: Fri, 3 Apr 98 18:00:29 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 3 Apr 1998     Volume: 8 Number: 2245

Today's topics:
        bitbucket for (,$b,,,$e,,)=split(/\,/,$string) <Robert.Lopez@abq.sc.philips.com>
    Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string) (Matthew Cravit)
    Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string) (Greg Bacon)
    Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string) (Abigail)
    Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string) <lr@hpl.hp.com>
    Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string) (Andrew M. Langmead)
    Re: changing perms w/CHMOD. (Greg Bacon)
    Re: current week (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
        DB_File and multiple processes otis@POPULUS.net
        Determining variable types (Chris Formulak)
    Re: Determining variable types <lr@hpl.hp.com>
    Re: Determining variable types (Andrew M. Langmead)
    Re: For all you newbies! Don't say I wasn't helpfull... <grinch@whoville.com>
    Re: How do I strip newlines from a var (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
    Re: How to tell if a script was executed directly (Andrew M. Langmead)
    Re: Is there a "Newsgroup" for Newbies to Perl? (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
    Re: long complicated system() call doesn't want to work (Andrew M. Langmead)
    Re: Number of Perl Users/Instalitations. <quillan@doitnow.com>
        Random numbers (Perl fails this test) (Tom Rokicki)
    Re: Sending an image <grinch@whoville.com>
    Re: SIGINT ? <prl2@lehigh.edu>
    Re: SIGINT ? <trid@we.be.catchin.spamz.at.primenet.com>
    Re: SIGINT ? <lr@hpl.hp.com>
        Silence is Golden <sneaker@mediaone.net>
        SUID perl? (Cal Sawyer)
    Re: Tie/bless vs. bless/tie and segmentation fault (Todd Lehman)
    Re: Tying a blessed hash (was: Re: Tie/bless vs. bless/ (Todd Lehman)
    Re: unpack vs. substr (was Re: Data Structure for Input (Jason Gloudon)
        Whois help <c2@3-g.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 03 Apr 1998 14:59:59 -0700
From: Robert Lopez <Robert.Lopez@abq.sc.philips.com>
Subject: bitbucket for (,$b,,,$e,,)=split(/\,/,$string)
Message-Id: <jc6yaxmftwg.fsf@abqn07.ato.sca.philips.com>

Using perl 5.004_04

Every perl book I have shows some use of split such as 
  ($login, $passwd, $uid, $gid, $gcos, $home, $shell)=split /:/;
but I find none of them address when not all fields are needed.

Using -w will lead to complaints of any lefthand var that is
not used after it is assigned. This lead me to use
  ($a,,$c,,,$f)=split ...
to satisfy perl -w. But now I want to do something
like
  (,$b,,,$e,,) and I find that the "(," is not going to work.

Do I have to do something like
  ($junk,$b,,,$e,,) ...
  undef($junk);
or is there some option I am missing? Is there a $bit_bucket ?

-- 
Robert Lopez                    <Robert.Lopez@abq.sc.philips.com>
Philips Semiconductors,   9201 Pan American Fwy. N.E.,   ms 20,
Albuquerque, New Mexico 87113 USA  [P: (505)822-7112  F: x7237]


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

Date: 3 Apr 1998 15:22:04 -0800
From: mcravit@shell3.ba.best.com (Matthew Cravit)
Subject: Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string)
Message-Id: <6g3qus$6vv$1@shell3.ba.best.com>

In article <jc6yaxmftwg.fsf@abqn07.ato.sca.philips.com>,
Robert Lopez  <Robert.Lopez@abq.sc.philips.com> wrote:
>Using perl 5.004_04
>
>Every perl book I have shows some use of split such as 
>  ($login, $passwd, $uid, $gid, $gcos, $home, $shell)=split /:/;
>but I find none of them address when not all fields are needed.
>
>Do I have to do something like
>  ($junk,$b,,,$e,,) ...
>  undef($junk);

In Perl 5.004, you can assign unneeded values to undef. So, you can write:

(undef,$b,,,$e,,) ...

or, you can do the following, which I find easier to read because you don't
have to count commas:

(undef,$b,undef,undef,$e,undef,undef) ...

/MC
-- 
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@net.com (work)      | time you make it.


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

Date: 3 Apr 1998 23:22:55 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string)
Message-Id: <6g3r0f$l5$1@info.uah.edu>

In article <jc6yaxmftwg.fsf@abqn07.ato.sca.philips.com>,
	Robert Lopez <Robert.Lopez@abq.sc.philips.com> writes:
: Using perl 5.004_04
: 
: Every perl book I have shows some use of split such as 
:   ($login, $passwd, $uid, $gid, $gcos, $home, $shell)=split /:/;
: but I find none of them address when not all fields are needed.

Here is a very cool trick that definitely belongs in any Perl hacker's
bag o' tricks:

    ($login, undef, $uid, undef, $gcos) = split /:/;

Assigning to undef in a list-to-list copy (llcp? :-) is essentially
catting to /dev/null.

It would be kind of cool if you could my would ignore undef so you
could slap a my() around the list, but such is not (currently) the
case.

Happy hacking,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 4 Apr 1998 00:16:05 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string)
Message-Id: <6g3u45$7e3$1@client3.news.psi.net>

Robert Lopez (Robert.Lopez@abq.sc.philips.com) wrote on MDCLXXVI
September MCMXCIII in <URL: news:jc6yaxmftwg.fsf@abqn07.ato.sca.philips.com>:
++ Using perl 5.004_04
++ 
++ Every perl book I have shows some use of split such as 
++   ($login, $passwd, $uid, $gid, $gcos, $home, $shell)=split /:/;
++ but I find none of them address when not all fields are needed.

(undef, $passwd, undef, undef, undef, undef, $shell) = split /:/;



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle 'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Additional/s) [0]'


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

Date: Fri, 03 Apr 1998 17:00:34 -0800
From: Larry Rosler <lr@hpl.hp.com>
To: abigail@fnx.com
Subject: Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string)
Message-Id: <35258632.BC41F146@hpl.hp.com>

Abigail wrote:
> 
> Robert Lopez (Robert.Lopez@abq.sc.philips.com) wrote on MDCLXXVI
> September MCMXCIII in <URL: news:jc6yaxmftwg.fsf@abqn07.ato.sca.philips.com>:
> ++ Using perl 5.004_04
> ++
> ++ Every perl book I have shows some use of split such as
> ++   ($login, $passwd, $uid, $gid, $gcos, $home, $shell)=split /:/;
> ++ but I find none of them address when not all fields are needed.
> 
> (undef, $passwd, undef, undef, undef, undef, $shell) = split /:/;
> 
> Abigail
> --
> perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle 'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Additional/s) [0]'

Or use an array slice:

  ($passwd, $shell) = (split /:/)[1, 6];

Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 4 Apr 1998 01:29:30 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: bitbucket for (,$b,,,$e,,)=split(/\,/,$string)
Message-Id: <Eqv857.G8H@world.std.com>

Robert Lopez <Robert.Lopez@abq.sc.philips.com> writes:

>Every perl book I have shows some use of split such as 
>  ($login, $passwd, $uid, $gid, $gcos, $home, $shell)=split /:/;
>but I find none of them address when not all fields are needed.

You can use subscripts to extract specific elements from a list, and
those lists can contain lists returned from functions. So just grab
the elements that you need.

($a,$c,$f) = (split /:/)[0,2,5];

Something that is occationally useful is that the order of the
elements that you grab in your slice does not need to be in increasing
numerical order.

($gcos, $login, $home, $uid) = (split /:/)[4,0,5,2];

Well, in this example, not too useful. (Except that if you feel that
certain variables are more important than others, you can put them
first.) If you are extracting into an array though, the order of the
elements that the function returns may not be the order that you want
to insert them to be in in the array.

 gcos, $login, $home, $uid

use constant GCOS => 0;
use constant LOGIN => 1;
use constant HOME => 2;
use constant UID => 3;
@userinfo = (split /:/)[4,0,5,2];

if($userinfo[UID]) {
 ...
}

Also notice where the parens are located. You can't say:

split(/:/)[0];

Because perl will complain:

Can't use subscript on split at - line 1, near "0]"

You have to have the function inside its own list enumerating parens, 
and grab the subscript of slice out of that:

(split(/:/))[0];
-- 
Andrew Langmead


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

Date: 3 Apr 1998 23:43:00 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: changing perms w/CHMOD.
Message-Id: <6g3s64$l5$2@info.uah.edu>

In article <jhill-0304981509450001@jhill-mac.mitre.org>,
	jhill@mitre.org (Jason C. Hill) writes:
: What I'm doing is an array of directories and in those directories I'm
: looking for files owned specifically by root [uid 0].  What I need to do
: is change all group and world permissions such that they aren't
: writeable.  My problems is I don't think I can issue a chmod command like
: this chmod g-w,o-w or something like that, I don't want to chnage any of
: the other bits incase some of them are sticky.  

Turn the bits off using the constants defined in POSIX.pm:

    use POSIX ':fcntl_h';

    ...

    ($dev, $ino, $mode, $nlink, $uid) = stat $j;
    $mode &= ~(S_IWGRP | S_IWOTH);

    chmod $mode, $j or warn "$0: failed chmod: $!";

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Sat, 04 Apr 1998 01:11:29 +0200
From: lassehp@imv.aau.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
Subject: Re: current week
Message-Id: <lassehp-0404980111300001@ygdrasil.imv.aau.dk>

In article <352b9018.4372084@news.tornado.be>, bart.mediamind@tornado.be
(Bart Lateur) wrote:

>Bob Trieger wrote:
>
>>a start would be:
>>
>>       @date = localtime();
>>       $week = $date[7]/7;
>
>Close. But it really depends on what day of the week the year starts
>with. In other words: the first week is but rarely a complete week.

On SGI, the date command has an option %V which gives the ISO 8601:1988
week number. Unfortunately, POSIX::strftime doesn't support this, although
it has other week numberings. (The problem is the first and last few days
of the year: which week do they belong to? The ISO week numbering has the
advantage that each week has only one week number, although a given day of
a year may belong to a week of a different year.

Based on this, I rolled my own strftime which supported %V and used it to
get week numbers. A kludge, for sure, but still better than doing `date
+"%V"`, and this way I can get any week number, not just today's.

However, upon reading this thread, I thought I might write a more
self-contained ISO 8601 week-number function.

According to the Calendar FAQ:
"Week 1 of any year is the week that contains 4 January"

The number of the first *whole* week (the first week of which all days,
mon-sun are in the year) is naturally either 1 or 2, because a partial
week could be week 1. The following table:

1234567 -date in January
0123456 -dayofyear (Jan 1 is 0)
        week #
FSSmTWT 1
SSMtWTF 1
SMTWTFL 1
MTWtFSS 1
TWTfSSM 2
WTFsSMT 2
TFSsMTW 2

shows that if jan4 is mon-thursday, then the first monday of the year is
in week 1 and if jan4 is fri-sunday, then the first monday is in week 2.

The monday in the week of the date supplied to week_number is either a
multiple of 7 days later than the first monday of the year or a monday in
the year before (and thus one week before).

Now to the function. I use Time::Local to get to the wday and yday fields
filled in given only a date y,m,d. I have used a liberal amount of
variables to make it clear what is happening. Of course this can be
reduced a lot, which is left to the reader. I also prefer providing a
month in the range 1..12, so I must adjust before calling timelocal.

sub week_number { my($year,$month,$day) = @_; # month is 1..12 !
    my $week;
    use constant THURSDAY => 3; # mon = 0, tue = 1, wed = 2, ...
    my($date_wday, $date_yday) =
        (localtime(timelocal(0,0,0,$day,$month-1,$year)))[6,7];
    $date_wday = ($date_wday + 6) % 7; # POSIX has sun==0, ISO 8601 has mon
    my($jan4_wday, $jan4_yday) =
        (localtime(timelocal(0,0,0,4,0,$year)))[6,7];
    $jan4_wday = ($jan4_wday + 6) % 7;

    my $date_weeks_monday = $date_yday - $date_wday;
    my $year_first_monday = $jan4_yday - $jan4_wday;
    $year_first_monday += 7 if $year_first_monday < 0;

    my $weeks_between; # between first_monday and date_weeks_monday
    if($date_weeks_monday < $year_first_monday) {
        # if the monday of this week is not the first monday
        # or a later monday:
        $weeks_between = -1;
    } else{
        $weeks_between = ($date_weeks_monday - $year_first_monday)/7;
    }
    my $first_mondays_week = ($jan4_wday <= THURSDAY)? 1:2;
    $week = $first_mondays_week + $weeks_between;
    # if you are content with having a week 0, the next line
    # could be omitted.
    $week = week_number($year-1,12,31) if $week == 0;
    return $week;
}

Now, a slightly more challenging exercise is to get the dates of the first
and last (or perhaps each) day of a given week in a year. Of course it
should also work across New Year.

Would there be interest in a Date::Weeks module providing these functions?

-Lasse


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

Date: Fri, 03 Apr 1998 17:47:39 -0600
From: otis@POPULUS.net
Subject: DB_File and multiple processes
Message-Id: <6g3ser$vu$1@nnrp1.dejanews.com>

Hello,

I would like to do this, but I'm not sure if it is possible:

script A uses DB_File and generates a DBM (by using DB_File).

I want to have scripts B and C that can read that DBM file and also delete
hash elements of that DBM that script A generates.

Can that be done?
Can scripts B and C read and modify (delete) elements of that hash at the same
time that script A is generating the file?

Does DB_File provide some kind of internal locking/serialization mechanism
that will allow me to have multiple processes modify the same DBM without
having to handle those acecsses myself?

Thanks

Otis
P.S.
If I use DB_File and HAVE Berkeley DB installed oon my machine, will DB_File
use Berkeley DB or something else? Thanks!

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 3 Apr 1998 22:44:22 GMT
From: formy@hill.ucr.edu (Chris Formulak)
Subject: Determining variable types
Message-Id: <6g3oo6$ebo$1@pravda.ucr.edu>

For a given variable, is there a way to tell if it contains a string or
a number?  For example, let's say I had two variables:

$str = "123";
$num = 123;

Is there a way that I can find out what type they are, maybe something
like this:

foreach $var ($str, $num) {
    if (isstr ($var)) {
        # This is a string so process it as such
    } else {
        # it's a number so do some other stuff
    }
}


where isstr is a function that returns true is the parameter passed to it 
is a string and false otherwise.

--

-Chris

Quote for the day (or week or month depending upon how long it takes me to
get around to changing it):

     "Think very hard about your future and your life.  Carefully write
      it down on a large piece of paper and flush it down the toilet."

-------------------------------------------------------------------------------
formy@cs.ucr.edu                                  http://www.cs.ucr.edu/~formy
cformulak@symantec.com                            http://www.cheesysoft.com


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

Date: Fri, 03 Apr 1998 17:30:53 -0800
From: Larry Rosler <lr@hpl.hp.com>
To: Chris Formulak <formy@hill.ucr.edu>
Subject: Re: Determining variable types
Message-Id: <35258D4D.712C9B@hpl.hp.com>

Chris Formulak wrote:
> 
> For a given variable, is there a way to tell if it contains a string or
> a number?

See perlfaq4:  "How do I determine whether a scalar is a
number/whole/integer/float?"

Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 4 Apr 1998 01:36:31 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Determining variable types
Message-Id: <Eqv8Gv.JAE@world.std.com>

formy@hill.ucr.edu (Chris Formulak) writes:

>For a given variable, is there a way to tell if it contains a string or
>a number?  For example, let's say I had two variables:

Have you seen the entry in the FAQ "How do I determine whether a
scalar is a number/whole/integer/float?" It discusses this subject.

<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/
How_do_I_determine_whether_a_sca.html>
-- 
Andrew Langmead


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

Date: Fri, 3 Apr 1998 17:05:50 -0500
From: "Grinch" <grinch@whoville.com>
Subject: Re: For all you newbies! Don't say I wasn't helpfull...
Message-Id: <6g3ln9$kp3@fridge.shore.net>

I R A Aggie wrote in message ...

>A repost out of my archives. This newbie problem isn't new...just
>seemingly infinite.


 ...snippus maximus...

Hear, hear. Well said!

-grinch

--
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





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

Date: Sat, 04 Apr 1998 02:13:17 +0200
From: lassehp@imv.aau.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
Subject: Re: How do I strip newlines from a var
Message-Id: <lassehp-0404980213200001@ygdrasil.imv.aau.dk>

In article <6g141i$9cs$1@client3.news.psi.net>, you wrote:

>Bryan Sapot (bsapot@office1.gundaker.com) wrote on MDCLXXV September
>MCMXCIII in <URL: news:6g11rf$pmf$1@newsin-1.starnet.net>:
>++ how can i strip new lines out at var.
>++ 
>
>Removing new lines is very tricky, as the manual tells you so.
>Ignore the complicated things in the manual, and put in this
>neat little trick:
>
>$var=join+q,,,grep{ord${qq$\137$}<10 or+10<ord}split+q,,,$var;
>
>If you're old enough not to read the manual, you won't have a
>problem understanding the above line.

While I agree that FAQs are a nuisance, I do wonder why you choose to post
an "answer" like that. What's your point?

If you want to refer to the FAQs, do so. If you want to complain to the
poster about posting a FAQ do so, preferably in E-mail. But if you just
want to insult or intimidate people (no matter whether they deserve it or
not), then please do so *elsewhere*.

It seems rudeness has become daily routine in c.l.p.m, and I think that of
all the newsgroups I have read since 1992 or so, c.l.p.m has the highest
rude/nice ratio. Flaming newbies here seems to have become the favorite
pastime of Perl hackers, and if such behaviour is now a fundamental part
of being a Perl hacker (as it seems), I guess it may be time to ask Jon
Orwant to cancel my subscription to The Perl Journal and find myself a
different language to hack in.

FAQs are not productive. But neither is arrogance and rudeness. May I
suggest you read Mark Moraes' periodic postings in news.announce.newusers
(again).

And the next time you see a FAQ here, please handle it in a productive
manner: _ignore_ it.

Please!

-Lasse

"Never Forget that the Person on the Other Side is Human."


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

Date: Fri, 3 Apr 1998 22:09:18 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: How to tell if a script was executed directly
Message-Id: <EquyvJ.KHD@world.std.com>

Bert Robbins <brobbins@tis.com> writes:

>Andrew Brown wrote:
>> My question is this:  is there any way for "myscript.pl" to detect whether
>> it has been executed directly or via a "do"?  I could check $0 and compare
>> it to the name of the script, but I don't wish to hardcode the script
>> name...

>Sure, go and take a look at the PPID, parent process id, and parent
>process.

The function do() does't start a separate process, so the PPID of code
in a file run from do() will be the same as the code that called it.

-- 
Andrew Langmead


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

Date: Sat, 04 Apr 1998 01:25:31 +0200
From: lassehp@imv.aau.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <lassehp-0404980125320001@ygdrasil.imv.aau.dk>

In article <news-0204981911430001@buzz.alink.net>, news@russo.org (Chris
Russo) wrote:

>In article <6g0ivc$daq@co-op.newsguy.com>, smitty77@pacbell.net wrote:
>
>>In article <news-0204980900530001@buzz.alink.net>, news@russo.org says...
>
>>>You're a very small man, basking in the limelight of your attempt to "take
>>>down" a celebrity.

>Haven't you done enough trolling for one week, sonny?
>
>Keep trying, though.  It reveals loads about you.

*PLONK*

-Lasse


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

Date: Fri, 3 Apr 1998 23:27:24 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: long complicated system() call doesn't want to work....
Message-Id: <Eqv2Ho.4L7@world.std.com>

"Human Resource Management" <jarviswalker@worldnet.att.net> writes:

>system("metasend -b -f \"$oufile\" -F \"website\" -i
>\"application/msword\" -m \"application/msword\" -t \"$email\" -s
>\"$outfile\" ");

>The syntax above works great from the command line, but when I try to submit
>the upload over httpd, it won't mail the file.

Does your perl script really have the call to system() on three lines?
Or did you wrap it to fit Usenet conventions.  In the shell, newlines
separate commands. In Perl, double quotes can span multiple lines,
keeping the embedded newlines. If you want to spread the system()
command over three lines, but want it to be only one command, one
solution would be to use the string concatination operator to join all
the strings together.

system("metasend -b -f \"$oufile\" -F \"website\" -i" .
"\"application/msword\" -m \"application/msword\" -t \"$email\" -s" .
"\"$outfile\" ");

another solution would be to use the list form of system(), avoiding
the shell and creating the other programs argument list from your
list.

system('metasend', '-b', '-f', $oufile, '-F', 'website', '-i',
'application/msword', '-m', 'application/msword', '-t', $email, '-s',
$outfile);

This also avoids a security weakness that may arise if the variables
contain shell metacharacters. (And if you don't know what I mean by
that, you might be better of having someone more knowledgeable,
perhaps a professional, to double check your work.)

The command may work from the command line (if it is not separated by
Newlines) but does the script? When you have the HTTP server run the
script on your behalf, does it emit any errors to the error log?

What does system() return? If it returned failure, what it the value
of the "$!" variable?

What does does the HTTP server supply you for a PATH environment
variable?  Does it include the directory you put metasend into? A lot
of people who have spent a lot of time with MS-DOS assume that the
current directory is always searched. Unix only does so if PATH
contains the "." directory. And if you don't know the pros and cons of
putting "." in your path, again, you might want to have a someone else
check your work.

A lot of these questions sound similar to the document 
<URL:http://language.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
have you read it?
-- 
Andrew Langmead


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

Date: Fri, 03 Apr 1998 18:14:29 -0700
From: "John C. Quillan" <quillan@doitnow.com>
Subject: Re: Number of Perl Users/Instalitations.
Message-Id: <35258975.D2A98795@doitnow.com>

Tom Phoenix wrote:
> 
> On Wed, 1 Apr 1998, John C. Quillan wrote:
> 
> > Subject: Re: Number of Perl Users/Instalitations.
> 
> > Actually I am just trying to get a ball park range.
> 
> There are 8,302,973 Perl programmers in the world, and Perl is installed
> on 173,290 machines. Wait, there's another one... :-)
> 
> You can make numbers which are more accurate than mine, I'm sure, but how
> could you prove it? Oh, well! :-)

I guess this was to much to ask.

I am well aware that it is going to be a gustimate.  What I was
looking for is some hard numbers, like books sold, downloads,
perl journal subscribers, etc.., that would help me get in
the right ball park.  Guess and General Smart remarks arn't
going to  help me a bit.

Thanks,

John C. Quillan


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

Date: 3 Apr 1998 15:11:53 -0800
From: rokicki@cello.hpl.hp.com (Tom Rokicki)
Subject: Random numbers (Perl fails this test)
Message-Id: <6g3qbp$qbm@cello.hpl.hp.com>


Perl's random numbers (from rand()) are atrocious---almost useless.
They just aren't very random.

The Perl docs point to Math-TrulyRandom, which is cool, but from the
 .pod file:

> The random numbers take a long time (in computer terms) to generate,
> so are only really useful for seeding pseudo random sequence generators.

So we can't use Math-TrulyRandom for simulations or anything like that.

There is also MathRandom, which is pretty spectacular and impressive,
but:

   1.  One heck of a lot of code when usually we only need simple random
       numbers, and

   2.  Not part of the standard distribution (thus I can't count on
       everyone having it).

I believe that Perl should provide an interface to drand48() and
friends (erand48(), lrand48(), nrand48(), mrand48(), jrand48(),
srand48(), seed48(), lcong48()) and use a different function (perhaps
random() derived from drand48()) as its default random number
generator.

Almost all platforms currently provide this set of functions, and I'm
sure it would be relatively straightforward to reimplement them if
necessary.  And drand48() works much better than rand().

   - Most users of rand() don't know how bad it is and wouldn't
     understand if we told them---and this generator might be
     horribly messing up results of their experiments!

   - Using drand48() to provide a work-alike to rand() called
     random(), and then deprecating rand(), would probably
     provide backwards compatibility while supporting a better
     future.

As a stop-gap, maybe interfaces to drand48()..lcong48() could be
made part of the builtin package?

Too bad drand48() isn't Posix.

-tom


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

Date: Fri, 3 Apr 1998 16:54:07 -0500
From: "Grinch" <grinch@whoville.com>
Subject: Re: Sending an image
Message-Id: <6g3l18$k2h@fridge.shore.net>

Pascal van Rossum wrote in message ...

>However, Netscape 3.x users see the javascript document.write
>that I use to write the IMG SRC tag to the screen.

Which indicates a problem with the JS, not with the CGI and especially not
with Perl.

Try one of the JS newsgroups, someone there may be able to help you.

-grinch


--
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





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

Date: Fri, 3 Apr 1998 17:31:17 -0500
From: "Phil R Lawrence" <prl2@lehigh.edu>
Subject: Re: SIGINT ?
Message-Id: <6g3nvm$1kuq@fidoii.cc.Lehigh.EDU>

Jonathan Feinberg wrote in message <4t0ashy0.fsf@mailhost.panix.com>...
>The perlipc doc suggests that on SYSVish systems (and therefore in
>the minds of all portability-minded scripters) you'll need to
>reinstall the signal handler, e.g.,
>
>   sub HANDLE_SIGINT {
>      print "Ouch, that smarts.\n";
>      $SIG{INT} = \&HANDLE_SIGINT;
>   }


Hmm.  Actually,

sub int_handler {
    print "Handled!\n";
    main();
    $SIG{"INT"} = \&int_handler;
}

gives same result as without reinstalling.  Also same result if I say:

sub int_handler {
    print "Handled!\n";
    $SIG{"INT"} = \&int_handler;
    main();
}

Anyone else getting these results from my test script?

>Read perlipc.
Thanks for the direction!  I'll read it.

Phil




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

Date: 3 Apr 1998 16:20:00 -0700
From: Todd Santos <trid@we.be.catchin.spamz.at.primenet.com>
Subject: Re: SIGINT ?
Message-Id: <6g3qr0$cah@nntp02.primenet.com>

stick $SIG{'INT'} = \&int_handler; in int_handler.

Phil R Lawrence <prl2@lehigh.edu> writes:
: In the following test script, I try to catch an interrupt signal and put
: myself back in main().  It works only once.  Then, if I issue another
: interrupt signal, ^C is written to the console and no signal is even
: recognized!  Why?  What can I do so that ^C will always send me back to
: main()?

: ________________________
: #!/usr/local/bin/perl -w
: use diagnostics;
: use strict;

: sub int_handler {
:     print "Handled!\n";
:     main();
: }
: $SIG{"INT"} = \&int_handler;

: sub main {
:     while (1) {
:         print "In main!\n";
:         my $x = <STDIN>;
:     }
: }

: main();
: __________________________

: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Phil R Lawrence               phone: 610-758-3051
: Programmer / Analyst      e-mail: prl2@lehigh.edu
: 194 Lehigh University Computing Center
: E.W. Fairchild - Martindale, Bldg. 8B
: Bethlehem, PA  18018
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



-- 
Bill Clinton
president@whitehouse.gov


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

Date: Fri, 03 Apr 1998 17:21:24 -0800
From: Larry Rosler <lr@hpl.hp.com>
To: trid@primenet.com
Subject: Re: SIGINT ?
Message-Id: <35258B14.F4221DC7@hpl.hp.com>

Todd Santos wrote:
> 
> stick $SIG{'INT'} = \&int_handler; in int_handler.
> 
> Phil R Lawrence <prl2@lehigh.edu> writes:
> : In the following test script, I try to catch an interrupt signal and put
> : myself back in main().  It works only once.  Then, if I issue another
> : interrupt signal, ^C is written to the console and no signal is even
> : recognized!  Why?  What can I do so that ^C will always send me back to
> : main()?
> 
> : ________________________
> : #!/usr/local/bin/perl -w
> : use diagnostics;
> : use strict;
> 
> : sub int_handler {
> :     print "Handled!\n";
> :     main();
> : }
> : $SIG{"INT"} = \&int_handler;
> 
> : sub main {
> :     while (1) {
> :         print "In main!\n";
> :         my $x = <STDIN>;
> :     }
> : }
> 
> : main();
> : __________________________
> 
> : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : Phil R Lawrence               phone: 610-758-3051
> : Programmer / Analyst      e-mail: prl2@lehigh.edu
> : 194 Lehigh University Computing Center
> : E.W. Fairchild - Martindale, Bldg. 8B
> : Bethlehem, PA  18018
> : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Try reestablishing the signal handler by moving the
$SIG{INT} = ... into main().

See the Blue Camel, p. 339 bottom - 341 top.  In some implementations,
"you had to reinstall the signal handler each time it got called."

Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Fri, 03 Apr 1998 23:38:40 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Silence is Golden
Message-Id: <3525718B.284E@mediaone.net>

In a recent episode...

Having returned to full strength, I turned 
my attention on the code portion of a post -

$rule = "perl is nice";
if ($rule =~ /p(e)r(l)( )(i)(s)( )(n)(i)(c)(e)/) {
    print "$5$4$2$1$7$9$10$3$8$5$6go$2d$1$7\n";
}

And I must say that is the nicest anyone has ever been to
me my whole life :-)  I will heed it's words of wisdom

:-)

(No, I will not leave, but will 'lurk about'...)

PS - Nice code.  It gives something to look forward to...


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

Date: 4 Apr 98 00:16:10 GMT
From: csawyer@eciad.bc.ca (Cal Sawyer)
Subject: SUID perl?
Message-Id: <35257bca.0@news.eciad.bc.ca>

Hi.

I'd like to build a set of perl CGI apps that allow our users to perform
certain ops on their files or establish vacation notification. I've been
reading on this a bit, but the methods for getting CGI scripts to execute 
SUID as invoking user are pretty hard to grasp, when you can find them at 
all. 

I wouldn't be above asking for/offering payment for a working starter kit 
to get the ball rolling. I know a lot of ISP's and Universities do this 
routinely but it's simply out of my area of expertise.

Any offers, help, advice, assitance deeply appreciated.

--
--------------------------------------- 
Cal Sawyer
Electronic Communication Design         
Emily Carr Institute of Art and Design 
Vancouver, B.C.  Canada                
--------------------------------------- 



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

Date: Sat, 04 Apr 1998 01:35:24 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: Tie/bless vs. bless/tie and segmentation fault
Message-Id: <w7gV.97$fh1.489012@ptah.visi.com>

Tye McQueen <tye@fohnix.metronet.com> writes:
> You are making circular references so these are destroyed only
> during global destruction and you can't predict the order in
> which it will happen.  If a tied object is destroyed before the
> Foo object that references that tied hash, then Foo::DESTROY
> will try to untie a hash from an object that has already been
> destroyed.

Aha, excellent.  That makes sense.


> lehman@javanet.com writes:
> ) sub DESTROY
> ) {
> )    my ($self) = @_;
> )    untie %$self;
> ) }
>
> Change that to
>
>    untie %$self   if  tied(%$self);
>
> and the core dump disappears and the depth of your problem
> becomes more apparent:
>
> untie attempted while 1 inner references still exist during global
> destruction.  Use of uninitialized value during global destruction.
> ...

One funny thing I noticed about

   untie %$self  if tied(%$self);

is that the "inner reference" to tied(%$self) seems to be retained
throughout the entire lexical scope of the 'if' conditional -- that is,
through and into the 'untie' call.  The retention of the reference can be
circumvented using a temporary boolean value:

   my $tied = !! tied %$self;
   untie %$self if $tied;

and now it neither dumps core nor complains about 1 inner reference
still existing.  :-)


> You need to remove the hard reference back to the first object
> so that it will be destroyed when it goes out of scope.  With
> Perl 5.004, I don't immediately see a solution if you really
> need the back reference.  Perl 5.005 is rumored to support weak
> references which might be appropriate here.

When you say "first object" do you mean the original hard reference from the
initial call to Foo::new?  It seems to be happy without doing that, due to
the temporary variable, I think.  I need to read more about reference
internals and garbage collection.

--Todd


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

Date: Sat, 04 Apr 1998 01:54:23 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: Tying a blessed hash (was: Re: Tie/bless vs. bless/tie and segmentation fault)
Message-Id: <jpgV.103$fh1.497112@ptah.visi.com>

John Porter <jdporter@min.net> writes:
> Well I'll be gosh darned.
>
> use Foo;
> my $obj = new Foo;
> $obj->{name} = 'john';
>
> The client's object, $obj, is a blessed hash-ref.
> But the object in the STORE method ($self) is a
> blessed array-ref.

Yup.  :-)


> I have to say, I'm not sure I'd build a large system
> dependent on this behavior.

I really was hesitant at first -- wondering whether it would even work
in the first place -- but I think it's all 100% kosher code, isn't it?
The only thing that (to me) seems dangerous to rely on in future versions
of Perl is the fact that it correctly handles blessing a hash which has
been tied.  But then, I don't know much about Perl internals.  Maybe this
sort of thing was thought about when tie was invented.


> So, how do the two objects communicate?  Do you have
> a field in the hash which refs the array? And vv?

Well, if you have a reference to the hash in $self, then you can always
get to the array using tied(%$self)->[...], so that's one way they could
communicate, or the outer object could pass messages to the inner object.
Unfortunately, the other direction isn't so easy...but fortunately, going
the other direction isn't necessary in the first place (at least not yet).

On another similar thread from about two weeks ago (egad this ng is big)
Tye McQueen suggested the following Jean-Louis Leroy:

> Perl will translate `$proxy_obj->{HASHKEY}' into `$object->FETCH("HASHKEY")'
> for you and your code can translate `$proxy_obj->SomeMethod()' into
> `$object->SomeMethod()' by having each method start like:
>
>    sub SomeMethod
>    {
>      my $self= shift(@_);
>        $self= tied(%$self)   if tied(%$self);
>        [...]
>    }

That's a pretty cool way to pass the message to the other object:
Instead of making the method call explicitly using $self->SomeMethod or
goto &SomeMethod, it simply loads the reference to the other object!
Perl rules!

--Todd


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

Date: Fri, 03 Apr 1998 23:26:46 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: unpack vs. substr (was Re: Data Structure for Input File)
Message-Id: <slrn6iarsn.e5t.jgloudon@manitoba.bbn.com>

Jeffrey R. Drumm <drummj@mail.mmc.org> wrote:
 .
 .
>If you've got to strip the nulls out of the variables you've extracted with
>substr(), there's an extra, somewhat expensive operation required (a tr/\0//d,
>for example).

tr won't do it though, a null terminated string may look like "some\0letters",
so tr won't strip the trailing garbage. s/\0.*$// might.

-- 
Jason Gloudon


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

Date: Thu, 02 Apr 1998 17:39:22 -0500
From: Chad Casselman <c2@3-g.com>
Subject: Whois help
Message-Id: <3524139A.CD354A38@3-g.com>

I need to know how to do a whois in perl.  Say that I have bsc.net I
want to know what company and state they are from.  How can you do this
in perl?

Thanks,
c2


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2245
**************************************

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