[18403] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 571 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 27 00:05:58 2001

Date: Mon, 26 Mar 2001 21:05:21 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985669521-v10-i571@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 26 Mar 2001     Volume: 10 Number: 571

Today's topics:
    Re: 'perl guy' wanted. <Ryan_J@Mac.Lover.org>
    Re: Basic socket logic (server) discussion... <uri@sysarch.com>
    Re: can @ENV be reset in the script? (David Efflandt)
    Re: CGI style - CGI vs "here is" vs ?? <gtoomey@usa.net>
        CGI: acceccing files on localhost ? <kellyboy@nospanner>
    Re: CGI: acceccing files on localhost ? (Damian James)
        correct date <troyr@vicnet.net.au>
    Re: correct date (Tad McClellan)
    Re: correct date (Martin Vorlaender)
    Re: fetch back STDERR outputs <johnlin@chttl.com.tw>
    Re: fetch back STDERR outputs <joe+usenet@sunstarsys.com>
        find & replace question <plz@righthere.com>
    Re: find & replace question <joe+usenet@sunstarsys.com>
    Re: find & replace question <wyzelli@yahoo.com>
        Help please. nospam@thank.you
        lines with headers kenta@nospam.nospam
    Re: lines with headers (Jay Tilton)
    Re: LWP help <gtoomey@usa.net>
    Re: one-liner assignment from regex (Tad McClellan)
        Packing/Unpacking C doubles in Perl <mcgrattm@cts.com>
    Re: Perl public key encryption (those who know me have no need of my name)
        Q: Active Perl redistributable MINIMUM? <jeremyk.remove-this@privacy.nu>
    Re: Reading Ms Word <Jonathan.L.Ericson@jpl.nasa.gov>
        Run wvdial from inside perl?? <acline@okstateREMOVECAPS.edu>
    Re: SIGHUP for restarting perl daemon (Charles DeRykus)
        sorting a list of files containing a numeric <kimmfc@mydeja.com>
    Re: sorting a list of files containing a numeric (Tad McClellan)
    Re: sorting a list of files containing a numeric (Jay Tilton)
    Re: sorting a list of files containing a numeric (Damian James)
        Swinging through the trees skipit@nospam.com
    Re: Swinging through the trees (Martien Verbruggen)
    Re: Swinging through the trees (Martien Verbruggen)
    Re: system() return value <kellyboy@nospanner>
    Re: system() return value (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Mar 2001 03:49:35 GMT
From: Ryan Junk <Ryan_J@Mac.Lover.org>
Subject: Re: 'perl guy' wanted.
Message-Id: <Ryan_J-9BC042.22482726032001@news.earthlink.net>

> Perl sees the apostrophe as the end of the string, unless it is
> preceeded by a backslash.  Therefore, you should process the comments
> field before feeding it to mysql.

Actually, I think here the problem is that MySQL sees the apostrophe as 
the end of the string, not that Perl sees the end of the string. In this 
case, you need to put in a double apostrophe so that MySQL doesn't get 
confused.
 
> You can use one of the following lines:
> 
> $comment=~ s/\'//g ;  # weed out all the ' characters
> $comment=~ s/\'/\\\'/g ;  # put a backslash in front of the ' characters

$comment=!s/\'/\'\'/g; # put another ' in front of the ' characters

Or just use 

$quotedcomment = $dbh->quote($comment);

as I believe a previous poster mentioned.

ryan


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

Date: Mon, 26 Mar 2001 23:50:50 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Basic socket logic (server) discussion...
Message-Id: <x7k85cytr9.fsf@home.sysarch.com>

>>>>> "w" == wdstaff  <lafondd@sympatico.ca> writes:

  >> 
  >> W, why can't you send data to a socket while it's taking input?
  >> 
  >> Chris
  >> 
  >> --

  w> Well, i tough that socket were blocked when they are utilize...
  w> So, if i get this right, i could "send & receive" at the same time
  w> on the same socket?

you got it. as i asked but you didn't answer, where did youget the
notion that sockets were half-duplex.

  w> thx for your nice reply, cant stand freaks that denigrate peoples.

ooo!! i am being called a freak by someone who can't use proper plurals
and calls us peeps.

you got more help than you deserve. you didn't just ask about how
sockets work you asked for someone to write your homework code:

<quote from previous post>

  w> go ahead and write the SERVER code...

  w> Credits and every infos you'd like will be incorporated to our final
  w> application. (Flash5 project)

  w> EMAIL ME BEFORE YOU MAKE A MOVE!

  w> details you must know before writing the code

</quote from previous post>

that was insulting and worthy of the massive denigration you got.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 27 Mar 2001 02:45:20 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: can @ENV be reset in the script?
Message-Id: <slrn9bvvlt.22r.efflandt@efflandt.xnet.com>

On Mon, 26 Mar 2001 15:06:31 -0600, Bing Du <bing-du@tamu.edu> wrote:
>If I set LD_LIBRARY_PATH=/public/lib from the command line and export it
>(I use zsh), the following script works fine.
>
>#!/public/bin/perl
>use SOAP::Lite;
>print "success";
>
>But if I set $ENV{'LD_LIBRARY_PATH'}="/public/lib" in the above script,
>I got the error:
>
>Can't load
>'/public/lib/perl5/site_perl/5.005/sun4-solaris/auto/XML/Parser/Expat
>/Expat.so' for module XML::Parser::Expat: ld.so.1: /public/bin/perl:
>fatal: libe
>xpat.so.0: open failed: No such file or directory at
>/public/lib/perl5/5.00501/s
>un4-solaris/DynaLoader.pm line 168.
>
> at /public/lib/perl5/site_perl/5.005/sun4-solaris/XML/Parser.pm line 15
>
>BEGIN failed--compilation aborted at
>/public/lib/perl5/site_perl/5.005/sun4-sola
>ris/XML/Parser.pm line 19.
>BEGIN failed--compilation aborted at
>/public/lib/perl5/site_perl/5.005/SOAP/Lite
>.pm line 739.
>BEGIN failed--compilation aborted at ./z.cgi line 6.
>
>How should I get 'LD_LIBRARY_PATH' set in the script?

'use' statements are executed during precompile before regular statements.  
So anything you need for 'use' would need to be placed before that in a
BEGIN block, or I wonder if 'use lib' would work (which unshifts to the
@INC search list during precompile):

use lib "/public/lib";
use SOAP::Lite;

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Tue, 27 Mar 2001 14:23:10 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: CGI style - CGI vs "here is" vs ??
Message-Id: <ioUv6.3967$45.20613@newsfeeds.bigpond.com>

I've been using Perl for a few months and am not an expert on optimisation
(yet).

However, saying that using eval is slower than a template is wrong.

When you use eval, you are using the Perl interpreter.

When you are using a template, your are using an interpreter (Perl)
that is used as a lexical anaylser for the template.
So with a template, you are using an interpreter for an interpreter.
Much slower.

I have been using the method I described for a few days.
I have timed it to take about 0.1 sec to generate a reasonably complex web
page.

gtoomey
---------------
"Uri Guttman" <
> wrote in message news:x73dc21akz.fsf@home.sysarch.com...
> >>>>> "GT" == Gregory Toomey <gtoomey@usa.net> writes:
>
>   GT> open(INFILE, 'home.htm');
>
>   GT> my @html=<INFILE>;
>
> why read it into an array only to join it? slurp it in as a single
> string by using $/
>
> $text = do{ local $/ ; <INFILE> } ;
>
>   GT> my $str= "<<EOF;\n".join("\n",@html)."\nEOF\n";
>
> why the join with \n? the lines already have \n on them.
> you could have just done a slurp and
>
> $str = "<<EOF;\n$text\nEOF\n" ;
>
>   GT> print eval $str;
>
> that is slow. use a simple s/// or a template module. and this is an FAQ
> as well.
>
> uri
>
> --
> Uri Guttman  ---------  uri@sysarch.com  ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page  -----------
http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net  ----------
http://www.northernlight.com




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

Date: Mon, 26 Mar 2001 22:39:10 -0600
From: "kellyboy" <kellyboy@nospanner>
Subject: CGI: acceccing files on localhost ?
Message-Id: <tc0666t4i57jc9@corp.supernews.com>

My home network is behind firewall..

Im writing script to list all image file in directory I supplied via
form...but dont seem to work...got "Internal Server Error"

is it because it limit the file access outside of cgi-bin?

here's the script:
#!/usr/local/bin/perl -w

use CGI qw(:standard);

print header, start_html("Graphic Explorer");

if (param()) {
 my $pathname = param("dir");
 chomp($pathname);"
 my @files = glob("$pathname/*.png");
 foreach $pix (@files) {
  print img(src=>$pix);
  print p("$pix\n");
 }
else {
 print p("Enter path to display .png files");
 print hr();
 print start_form();
 print p("Pathname: ", textfield("dir"));
 print p(submit("Get"). reset("Clear"));
 print end_form(),hr();
}
print end_html;

how do I get to that directory that is outside of /usr/local/apache?

security is not much of a issue for me because im behind firewall and Im the
only person in this house using the computer

kellyboy
--





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

Date: 27 Mar 2001 04:58:38 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: CGI: acceccing files on localhost ?
Message-Id: <slrn9c07eq.cnu.damian@puma.qimr.edu.au>

kellyboy chose Mon, 26 Mar 2001 22:39:10 -0600 to say this:
>...
>how do I get to that directory that is outside of /usr/local/apache?
>
>security is not much of a issue for me because im behind firewall and Im the
>only person in this house using the computer
>

Create a symlink to it somewhere under your document root directory
(htdocs?). Try typing 'man ln' in your shell to get the syntax. You might
need to add FollowSymLinks to the Options list for the document root's
Directory directive.

This is a web server configuration issue that has nothing whatsoever to
do with Perl. 

HTH

Cheers,
Damian
-- 
@;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
+1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker


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

Date: Tue, 27 Mar 2001 10:17:11 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: correct date
Message-Id: <o0Rv6.2823$R.108018@ozemail.com.au>

Hi there,
            Is there a standard module which accepts a date..and returns a
positive value if its a valid date. Ie returns 0 for 31st of feb 2000 but
returns 1 for 28th of feb 2000

Thanks in advance



----------------------------------------------------------------
Troy Rasiah
Melbourne, Aus




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

Date: Mon, 26 Mar 2001 20:43:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: correct date
Message-Id: <slrn9bvs14.9tv.tadmc@tadmc26.august.net>

Troy Boy <troyr@vicnet.net.au> wrote:

>            Is there a standard module which accepts a date..and returns a
>positive value if its a valid date.


   use Date::Calc qw(check_date);


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


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

Date: Tue, 27 Mar 2001 04:08:27 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: correct date
Message-Id: <3abff61b.524144494f47414741@radiogaga.harz.de>

Troy Boy (troyr@vicnet.net.au) wrote:
> Is there a standard module which accepts a date..and returns a
> positive value if its a valid date. Ie returns 0 for 31st of feb 2000 but
> returns 1 for 28th of feb 2000

IMHO, if you don't use any other date functions, a module would be overkill.

sub is_leapyear ($) # year
{
	$_[0] % 4 == 0 && ($_[0] % 100 != 0 || $_[0] % 400 == 0)
}

sub days_in_month ($$) # month, year
{
	($_[0] == 2)
		? (is_leapyear($_[1]) ? 29 : 28)
		: (($_[0] =~ /^(?:4|6|9|11)$/) ? 30 : 31)
}

sub is_valid_date ($$$) # day, month, year
{
	   $_[2] >= 1
	&& $_[1] >= 1 && $_[1] <= 12
	&& $_[0] >= 1 && $_[0] <= days_in_month($_[1],$_[2])
}

sub check_date ($) # "dd.mm.yyyy"
{
	   3 == ($_[0] =~ /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/)
	&& is_valid_date($1,$2,$3);
}


cu,
  Martin
-- 
One OS to rule them all       | Martin Vorlaender  |  VMS & WNT programmer
One OS to find them           | work: mv@pdv-systeme.de
One OS to bring them all      |   http://www.pdv-systeme.de/users/martinv/
And in the Darkness bind them.| home: martin@radiogaga.harz.de


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

Date: Tue, 27 Mar 2001 09:04:52 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: fetch back STDERR outputs
Message-Id: <99oosn$9ek@netnews.hinet.net>

nobull wrote
> Of course you best thing to do would probably be to ditch the old
> filehandle syntax and use only the modern filehandle reference syntax
> so that you can use my() and don't have to worry about local().  You
> may even want to switch to the OO syntax (the IO::* modules) so that
> files look just like any other object in Perl.

Oh, great!!!  It touches another problem of mine.  I DID try it:

my $err;
open $err,"+>>test.err" or die $!;
open STDERR,">>&$err" or die $!;    # for a dup

Error Message: Invalid argument at line 3.

OK, let me try:

open STDERR,">>& $err" or die $!;
open STDERR,">> &$err" or die $!;
open STDERR,">>&",$err or die $!;  # 3 argument open
open STDERR,">>","&$err" or die $!;

or

use IO::File;
my $err = new IO::File;
# the same trials ...

all failed.  Hmm...  :(

Was I doing something stupid?

Thank you.

John Lin






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

Date: 26 Mar 2001 20:22:56 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: fetch back STDERR outputs
Message-Id: <m3vgow9f9r.fsf@mumonkan.sunstarsys.com>

"John Lin" <johnlin@chttl.com.tw> writes:

> Oh, great!!!  It touches another problem of mine.  I DID try it:
> 
> my $err;
> open $err,"+>>test.err" or die $!;
> open STDERR,">>&$err" or die $!;    # for a dup
> 
> Error Message: Invalid argument at line 3.
> 
> OK, let me try:
> 
> open STDERR,">>& $err" or die $!;
> open STDERR,">> &$err" or die $!;
> open STDERR,">>&",$err or die $!;  # 3 argument open
> open STDERR,">>","&$err" or die $!;
> 
> or
> 
> use IO::File;
> my $err = new IO::File;
> # the same trials ...
> 
> all failed.  Hmm...  :(
> 
> Was I doing something stupid?

Did you read 

  % man perlopentut

? It discusses this issue as well as a 
workaround using fileno().

-- 
Joe Schaefer           "Wise men make proverbs, but fools repeat them."
                                               -- Samuel Palmer



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

Date: Mon, 26 Mar 2001 15:28:31 -0800
From: "B McDonald" <plz@righthere.com>
Subject: find & replace question
Message-Id: <1iQv6.63$224.88839@news.pacbell.net>


Hi. What is better: to test for the presence of a character in a string
before replacing it, or to just attempt the substitution without testing?

For example, I have a string that can take on one of the following values:

    Attorneys Eyes Only
    Attorneys' Eyes Only

The preferred XML encoding of the security level is without the apostrophe.

So, should I just do this...

    $securitylev =~ s/\'//g;

Or should I test it first?

Brian




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

Date: 26 Mar 2001 19:07:34 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: find & replace question
Message-Id: <m3zoe89ird.fsf@mumonkan.sunstarsys.com>

"B McDonald" <plz@righthere.com> writes:

  $_ = <<'QUOTE';
> The preferred XML encoding of the security level is without the apostrophe.
> 
> So, should I just do this...
> 
>     $securitylev =~ s/\'//g;
> 
> Or should I test it first?
QUOTE

  s/\bor\b/and/gi;

  print $eightball->magic( tr/'//d );


-- 
Joe Schaefer     "A cynic is a man who knows the price of everything and the
                                      value of nothing."
                                               --Mark Twain


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

Date: Tue, 27 Mar 2001 09:54:30 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: find & replace question
Message-Id: <eUQv6.7$aF1.3014@vic.nntp.telstra.net>

"B McDonald" <plz@righthere.com> wrote in message
news:1iQv6.63$224.88839@news.pacbell.net...
>
> Hi. What is better: to test for the presence of a character in a
string
> before replacing it, or to just attempt the substitution without
testing?
>
> For example, I have a string that can take on one of the following
values:
>
>     Attorneys Eyes Only
>     Attorneys' Eyes Only
>
> The preferred XML encoding of the security level is without the
apostrophe.
>
> So, should I just do this...
>
>     $securitylev =~ s/\'//g;

That backwack is not needed.

> Or should I test it first?
>

I would just do the substitution, though for a single character (or a
list of charcters) I would use tr///

I _would_ test if there was a chance that there were other apostrophes
which I might not want to change.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





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

Date: Tue, 27 Mar 2001 04:46:08 GMT
From: nospam@thank.you
Subject: Help please.
Message-Id: <3ac018ec.34395177@news.freeserve.co.uk>

Hi,

I've written a simple Perl script which creates an emailing list ie, a
user enters their email address into a html form, the script adds
their email address to the list. This works fine at the moment but is
it possible to locate the list file somewhere other than in the
cgi-bin or a cgi-bin sub-directory - In other words I'd like to
store/host the list file in another domain. eg.
www.somewhere.else.com/list/list.txt

I'm currently using;

$file = "maillist/maillist.txt";

to store the file name .


Thanks in advance :-)


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

Date: 26 Mar 2001 03:07:45 GMT
From: kenta@nospam.nospam
Subject: lines with headers
Message-Id: <99mbq1$bo0$1@news.netmar.com>

Hi, I'm looking for advice to make this program more "elegant."

#!perl -w
$first_time=1;
while(<>){
  chomp;
  unless (/^\d*$/){
    print "$title=$sum\n" unless $first_time;
    $title=$_;
    $first_time=0;
    $sum=0;
    next;
  }
  $sum+=$_;
}
print "$title=$sum\n" unless $first_time;

It reads a header line, then sums the next lines until another
header.  Sample input:

foo
1
2
3
bar
4
5

Sample output

foo=6
bar=9

So, is there anyway to avoid duplicating the "print" 
statement at the end?

This is a simplified example of a general problem 
I keep having over and over again.

Thanks,
--k




 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Tue, 27 Mar 2001 02:40:35 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: lines with headers
Message-Id: <3abfecf2.147251611@news.erols.com>

On 26 Mar 2001 03:07:45 GMT, kenta@nospam.nospam wrote:

>#!perl -w
>$first_time=1;
>while(<>){
>  chomp;
>  unless (/^\d*$/){
>    print "$title=$sum\n" unless $first_time;
>    $title=$_;
>    $first_time=0;
>    $sum=0;
>    next;
>  }
>  $sum+=$_;
>}
>print "$title=$sum\n" unless $first_time;

>So, is there anyway to avoid duplicating the "print" 
>statement at the end?

It wouldn't be Perl without TIMTOWTDI.
There's a hash-based approach.

   my (%sum_hash, $title);
   while(<>){
      chomp;
      unless (/^\d*$/) {
         $sum_hash{$title = $_} = 0;
         next;
      }
      $sum_hash{$title} += $_;
   }
   print map {"$_=$sum_hash{$_}\n"} keys %sum_hash;

Or you can invert some of the flow control.

   my ($title, $sum);
   do {
      while (<>) {
         chomp;
         last unless /^\d*$/;
         $sum += $_;
      }
      print "$title=$sum\n" if defined $title;
      $title = $_;
      $sum = 0;
   } until eof


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

Date: Tue, 27 Mar 2001 14:39:52 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: LWP help
Message-Id: <YDUv6.3977$45.20623@newsfeeds.bigpond.com>

You can set the timeout as given below.

I don't know about limiting the bytes received - there are usually only
about 5000 bytes
to a  page so this downloads in about 1 sec. Remember, you are not
downloading
the images (.gif for .jpg).

gtoomey
(Greetings from sunny Australia! Beautiful one day, perfect the next ;-)
----
use LWP::UserAgent;
use HTTP::Cookies;

      $ua = new LWP::UserAgent;
      $ua->agent("$0/0.1 " . $ua->agent);
      $ua->timeout(30); # change your timout value as necessary
       $req = new HTTP::Request 'GET' => 'http://www.somesite.com';  #change
as apprporiate
      $req->header('Accept' => 'text/html');
      $res = $ua->request($req);

      if ($res->is_success) {
                #web page is now in the variable$res
}

-------------
"Eric" <mail@ericmarques.net> wrote in message
news:NrMv6.21412$PF4.29991@news.iol.ie...
> I am using LWP::UserAgent
> How do i set a timeout and maximum recieve data?
>
>
> --
> Eric Marques
> mail@ericmarques.net
>
>




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

Date: Mon, 26 Mar 2001 19:04:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: one-liner assignment from regex
Message-Id: <slrn9bvm7m.9tv.tadmc@tadmc26.august.net>

Kevin Lacquement <klacquement@syscor.com> wrote:
>>>>>> "KC" == Kim C <kimmfc@mydeja.com> writes:
>
>[...]
>
>    KC> 	($start , $end) = /(^.)(.$)/;
>
>What does this actually match?  


two-character strings (or three chars if the last is a newline).


>I'd think it gets everything, 


What part of the pattern matches lots of characters?


>but what
>would be in $1 


same as:

   substr($_, 0, 1);    # the first character from $_


>and $2?

   substr($_, -1);      # if no newline

   substr($_, -2, 1);   # if with newline


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


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

Date: Mon, 26 Mar 2001 20:42:05 -0800
From: Michael McGrattan <mcgrattm@cts.com>
Subject: Packing/Unpacking C doubles in Perl
Message-Id: <3AC01A1D.211B@cts.com>

In Perl 5.005_03, I am trying to read a file that is generated 
by a C program that is packing all data in network byte order, 
including doubles.  All data being generated and read resides 
on the same linux machine (so O/S or network anomalies do not 
exist in this case).  Each 'data set' consists of 7 4BYTE 
elements and 1 8BYTE double for total of 36 BYTES.  The
7 4BYTE elements are either hex or ints and I can read those fine.  
The problem is unpacking the double.  When I try to display the 
value, it is an enormous number.  I expect the value to be 
like 0.18 or 0.24, but I get something like 1071602728 when unpacking 
using "N" or something like 7.38736860443349e+137 when unpacking 
using "d".  I am reading and unpacking as follows:

  open(FILE,$ARGV[0]);
  while ($readLen = sysread FILE,$element,$numBytes,0)
  {
     $mod=$cnt%8;
     if ($mod==1)
     {
        #*****************UNPACK HEX*****************
        $unpackElement=unpack "N", $element;
        $hexValue=sprintf "%lx",$unpackElement;
        print STDOUT "$hexValue";
     }
     else
     {
        #************UNPACK INTS AND DOUBLE***********
        print STDOUT unpack "N", $element;
     }

     if ($mod==7)
     {
        $numBytes=8;
     }
     else
     {
        $numBytes=4;
     }
     $cnt+=1;
  }
  close(FILE);


Is there something special about unpacking doubles generated by C 
that were packed in network byte order?  

Additionally, the only way I can try to mimic generating a 8BYTE
value and writing it to a file (trying to reverse engineer what 
may be happening) is to first pack it using "d" (pack "d", $data) 
and then write it to a file.  How do you pack a 8BYTE value 
using "N" (pack "N", $data).  If you first pack using "d" and 
then pack that result with "N", the variable goes from 8BYTES to 
4BYTES.  Whenever I pack using "N", it always uses 4BYTES.  How can 
you pack just using "N" and have the value be 8BYTES?


Thank you

Michael


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

Date: Tue, 27 Mar 2001 02:33:49 -0000
From: not-a-real-address@usa.net (those who know me have no need of my name)
Subject: Re: Perl public key encryption
Message-Id: <tbvv0drv05dg5d@news.supernews.com>

[note: this is really a security rather than a cryptography issue]

<wyBv6.50241$g63.6757199@nnrp3.clara.net> divulged:

>I suppose the encrypted data from the remote browser will be decrypted
>by Apache HTTP server and passed on to the Perl program. The Perl
>program will then encrypt it again before writing it to a file on the
>webserver. 

 ... provided the perl program hasn't been tampered with.

anyway, you might want to see if they have pgp or gpg installed, then you
can use Crypt::PGP2, Crypt::PGP5, or Crypt::GPG.  be careful not use
write a temporary cleartext file.

>But, incidentally, getting the data to my PC is another reason
>why I want the data to be encrypted, since my ISP doesn't support secure
>FTP. 

umm.  use https: to transfer the files.

-- 
okay, have a sig then


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

Date: Mon, 26 Mar 2001 18:08:43 -0500
From: Jeremy <jeremyk.remove-this@privacy.nu>
Subject: Q: Active Perl redistributable MINIMUM?
Message-Id: <3ABFCBFB.D170165C@privacy.nu>

Hello, Gurus.

Does anyone know what the absolutely minimal Active Perl installation
consists of? Assume I use no packages, only the very core perl
functionality, what do I need to install on a machine in order to be
able to run it? (The old perl was easy in that respect, while the
"Active" perl is too Window'ish, takes huge amount of space on disk,
installs fifty bazillion files, and probably puts something in the
Registry.) I need to move it quickly though, and nonintrusively in terms
of machine configuration.

Any ideas?

Thanks.


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

Date: 27 Mar 2001 03:51:29 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Reading Ms Word
Message-Id: <86ae673m4e.fsf@jon_ericson.jpl.nasa.gov>

"Tom" <tom@hotversion.com> writes:

> Is it possible to use perl to access Ms Word documents at all ?

Yes.

search.cpan.org might help you find a module that does what you want.
If not, why don't you write one?

Jon


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

Date: Mon, 26 Mar 2001 21:11:26 -0600
From: Aaron Cline <acline@okstateREMOVECAPS.edu>
Subject: Run wvdial from inside perl??
Message-Id: <EuTv6.288$Rx.3349@news.onenet.net>

Hello:

I want to be able to activate wvdial (internet connection) without going 
away from my perl script.  

I've tried

`wvdial &`;
$done=`wvdial &`;
system('wvdial &') == 0 or die;
system('wvdial &');
system(wvdial &);


etc.... everytime I run it this way, the script runs wvdial but shows all 
the output on the console and stays with it because it doesn't terminate.

Any help?

Aaron Cline


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

Date: Tue, 27 Mar 2001 01:32:27 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: SIGHUP for restarting perl daemon
Message-Id: <GAu1M3.GFo@news.boeing.com>

In article <3ABBC124.1DBC47C1@hotmail.com>,
Marc Bigler  <N_O_S_P_A_M_syn_uw@hotmail.com> wrote:
>Hello,
>
>I would like to use the signal HUP to restart a perl base daemon. The
>problem that I am getting is the following: the first kill -HUP on the
>perl process will work perfectly, restarting my perl daemon, great! But
>if then I do again a kill -HUP to restart it again then no reactions
>from my daemon, it still works but it just seems that it doesn't want to
>process anymore my HUP.
>
>Here is the code I use to do that:
>
>
>sub reinitialize {
>
> print "HUP signal received, reinitializing server...\n";
> print "DEBUG: Closing server socket\n";
> close(SERVER_SOCKET) or warn "Can't close listen socket: $!\n";
>
> print "Killing childrens if any...\n";
> kill_childrens();
>
> unlink PID_FILE;
> chdir("/tmp");
> sleep 1;
> exec(SELF) or die("ERROR: Couln't restart");
>
>}
>...

Signals can be problematic at best and i/o in
particular isn't reentrant and should be avoided. 
So C<print> is out. In fact, a minimal handler is 
perferable, i.e, just setting a flag: 

my $got_hup;
$SIG{HUP} = sub { $got_hup = 1 };

LOOP: {
    ...
    &reintialize if $got_hup;
}


--
Charles DeRykus


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

Date: Tue, 27 Mar 2001 00:07:31 GMT
From: Kim C <kimmfc@mydeja.com>
Subject: sorting a list of files containing a numeric
Message-Id: <pulvbt04efjs0m22gf44gnd0n0hn21jcmt@4ax.com>

Hi,

How do I sort a list of automaticaly-generated files that consist of a
constant string followed by a numeric?  Here's the catch: the numeric
is in the format 8, 9, 10, 11... rather then the easy-to-sort format
08, 09, 10, 11....

For example:

constant_string_8.log
constant_string_9.log
constant_string_10.log
constant_string_11.log
etc ...

so to sort using {$a <=> $b} on a long list would produce:

constant_string_58.log
constant_string_59.log
constant_string_6.log	## Uh oh!
constant_string_60.log
constant_string_61.log
etc ...

So, without appending a leading '0' to digits less than 10, how can I
sort the above list by the numeric?

Thanks

Kim C.


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

Date: Mon, 26 Mar 2001 20:40:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sorting a list of files containing a numeric
Message-Id: <slrn9bvrru.9tv.tadmc@tadmc26.august.net>

Kim C <kimmfc@mydeja.com> wrote:
>
>How do I sort a list of automaticaly-generated files 


Cannot be done, unless you define how one file can be "less than"
another file.


>that consist of a
>constant string followed by a numeric?  Here's the catch: the numeric
>is in the format 8, 9, 10, 11... rather then the easy-to-sort format
>08, 09, 10, 11....


It looks to me like you do not want to sort files.

Looks like you want to sort file_names_.

A "file" and the "name of a file" are not the same thing.


>so to sort using {$a <=> $b} on a long list would produce:


That sorts on the entire string. You don't want to compare the
entire string. You want to compare part of it. So write code
that gets you the part you are interested in (the digits).


>constant_string_58.log
>constant_string_59.log
>constant_string_6.log	## Uh oh!
>constant_string_60.log
>constant_string_61.log
>etc ...
>
>So, without appending a leading '0' to digits less than 10, how can I
>sort the above list by the numeric?


I'd start with the way suggested in the Perl FAQ.

   "How do I sort an array by (anything)?"


Then modify it to grab the part you want to sort on:

 my @sorted = map  { $_->[0] }
              sort { $a->[1] <=> $b->[1] }
              map  { [ $_, /^constant_string_(\d+)\.log$/ ] } @data;


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


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

Date: Tue, 27 Mar 2001 03:02:02 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: sorting a list of files containing a numeric
Message-Id: <3ac000ff.152385542@news.erols.com>

On Tue, 27 Mar 2001 00:07:31 GMT, Kim C <kimmfc@mydeja.com> wrote:

>so to sort using {$a <=> $b} on a long list would produce:
>
>constant_string_58.log
>constant_string_59.log
>constant_string_6.log	## Uh oh!
>constant_string_60.log
>constant_string_61.log
>etc ...
>
>So, without appending a leading '0' to digits less than 10, how can I
>sort the above list by the numeric?

Sounds like a good candidate for Schwartzian Transform.

my @sorted = map {$_->[0]}
             sort {$a->[1] <=> $b->[1]}
             map {/^constant_string_(\d+?)\.log$/; [$_, $1]}
             @array;

For details:
  perldoc -q "How do I sort an array by (anything)?"


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

Date: 27 Mar 2001 03:20:25 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: sorting a list of files containing a numeric
Message-Id: <slrn9c01ml.7mk.damian@puma.qimr.edu.au>

Kim C chose Tue, 27 Mar 2001 00:07:31 GMT to say this:
> ...
>
>constant_string_8.log
>constant_string_9.log
>constant_string_10.log
>constant_string_11.log
>etc ...
>
>so to sort using {$a <=> $b} on a long list would produce:
>
>constant_string_58.log
>constant_string_59.log
>constant_string_6.log	## Uh oh!
>constant_string_60.log
>constant_string_61.log
>etc ...
>

Well, you can't be using {$a <=> $b}, because -w would be complaining:

	Argument "constant_string_8.log" isn't numeric in sort at $0 line $line.

This is a prime candidate for the Schwartzian Transform (see below).

>So, without appending a leading '0' to digits less than 10, how can I
>sort the above list by the numeric?

By sorting on the numeric value. Look at this test:

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

my @bleh = map { "test_$_" } 0..99;
@bleh = reverse @bleh;

print "@bleh\n\n";
print "@{[ sort @bleh ]}\n\n";	# sorts by string, ie, { $a cmp $b }

#print "@{[ sort { $a <=> $b } @bleh ]}\n"; # generates warnings, 
											# doesn't sort

print "@{			
    [									# read this lot backwards:
        map { $_->[0] }					# keep the original data
        sort {$a->[1] <=> $b->[1]}		# sort it numerically
        map { [ $_, /^test_(\d+)/ ] }	# extract the data to sort by
        @bleh							# the array to be sorted
    ]
}\n";
__END__

This is a FAQ. You might want to have a look at the answer provided by:

	perldoc -q sort
	'How do I sort an array by (anything)?'

HTH

Cheers,
Damian
-- 
@;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
+1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker


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

Date: Tue, 27 Mar 2001 04:25:02 GMT
From: skipit@nospam.com
Subject: Swinging through the trees
Message-Id: <3ac01623.12612605@news.earthlink.net>

I am trying to build a list of all files and subdirectories in another
directory.  I have figured out how to list the subdirectories, but not
the contents of these directories.

Here is my script:

#!/usr/bin/perl -w

opendir MUSICDIR, "D:\mymusi~1";
@categories = grep !/^\.\.?$/, readdir MUSICDIR;
closedir MUSICDIR;

foreach $subdir(@categories) {
	opendir (SUBDIR, "D:\mymusi~1\$subdir") or die"Couldn't open
directory\n";
	@tracks = grep !/^\.\.?$/, readdir SUBDIR;
 ...

Now why doesn't this work?

Thanks



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

Date: Tue, 27 Mar 2001 04:40:47 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Swinging through the trees
Message-Id: <slrn9c06ef.jrg.mgjv@verbruggen.comdyn.com.au>

On Tue, 27 Mar 2001 04:25:02 GMT,
	skipit@nospam.com <skipit@nospam.com> wrote:
> I am trying to build a list of all files and subdirectories in another
> directory.  I have figured out how to list the subdirectories, but not
> the contents of these directories.

Check out the File::Find module. It's installed as part of Perl.

> Here is my script:
> 
> #!/usr/bin/perl -w

no use strict;

> opendir MUSICDIR, "D:\mymusi~1";

You're not checking return values here. You should either double your
backslashes, or use forward slashes

"D:/mymusi~1"

> @categories = grep !/^\.\.?$/, readdir MUSICDIR;
> closedir MUSICDIR;
> 
> foreach $subdir(@categories) {
> 	opendir (SUBDIR, "D:\mymusi~1\$subdir") or die"Couldn't open
> directory\n";

A better error message would include $!.

What you have there, becomes the string 'D:mymusi~1$subdir', which is
hardly what you wanted. Use normal slashes,

"D:/mymusi~1/$subdir"

or double the backwhacks

"D:\\mymusi~1\\$subdir"

opendir SUBDIR, "D:/mymusi~1/$subdir" or 
	die "Couldn't opendir 'D:/mymusi~1/$subdir': $!\n";

> Now why doesn't this work?

Next time, when you say "doesn't work", please be a bit more
descriptive: Any error messages? If so, which ones? Behaviour
different from what you expect? If so, what did you expect, and what
happened? Nuclear missiles started dropping on your back lawn? If so,
which type, and how heavy? The cat suddenly got loopy? If so, what did
it do, and what's its name?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.   | Universe and Reboot +++
NSW, Australia                  | 


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

Date: Tue, 27 Mar 2001 04:42:17 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Swinging through the trees
Message-Id: <slrn9c06h9.jrg.mgjv@verbruggen.comdyn.com.au>

> On Tue, 27 Mar 2001 04:25:02 GMT,
> 	skipit@nospam.com <skipit@nospam.com> wrote:
>> @categories = grep !/^\.\.?$/, readdir MUSICDIR;
>> closedir MUSICDIR;

Oh, since you're only interested in subdirectories, you should
probably include a -d test in the grep.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Can't say that it is, 'cause it
Commercial Dynamics Pty. Ltd.   | ain't.
NSW, Australia                  | 


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

Date: Mon, 26 Mar 2001 20:52:38 -0600
From: "kellyboy" <kellyboy@nospanner>
Subject: Re: system() return value
Message-Id: <tbvvufqh1joe3b@corp.supernews.com>

Really what I was asking is:

In perl, 0 or nul1 is considering false; anything else is true.

So, when in a program or anything else, if the return value is 0, it means
success, so I equate "success" with "true" while "error" = false

So in perl:
0=false
1(or more)=true

in program return value:
0=success
1(or error)=error

Im asking to make sure that in the case of system(), return value of 0
(depending on command I'm using)really mean 'success' despite that in perl
language it means false.

I've been learning perl few weeks and I get confused with system()....

but I understand whole thing tho...

thanks anyway

kellyboy

> > if (system(something)) {
> >     im here cuz system return error
> >     }
> >     else {
> >     im here cuz system return 0 which mean success
> > }
> >
>
> Yes, that's correct; but I don't see what your question is actually.
>
http://fusshuhn.ourfamily.com/cppincomp.html




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

Date: Tue, 27 Mar 2001 04:15:46 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: system() return value
Message-Id: <slrn9c04vj.jrg.mgjv@verbruggen.comdyn.com.au>

[Please, in the future, put your reply _after_ the suitably trimmed
text you reply to. It's the generally accepted quoting style on this
group, and Usenet in general]

On Mon, 26 Mar 2001 20:52:38 -0600,
	kellyboy <kellyboy@nospanner> wrote:
> kellyboy
> 
>> > if (system(something)) {
>> >     im here cuz system return error
>> >     }
>> >     else {
>> >     im here cuz system return 0 which mean success
>> > }
>> >
>>
>> Yes, that's correct; but I don't see what your question is actually.
>>
> 
> Really what I was asking is:
> 
> In perl, 0 or nul1 is considering false; anything else is true.

In Perl, false is normally represented by 0, "0", "" or undef. Oh, and
in a list context, the empty list is false.

What is nul1?

> So, when in a program or anything else, if the return value is 0, it means
> success, so I equate "success" with "true" while "error" = false

No. A subroutine or function returns what it returns. _Many_ functions
and subroutines return a true value for succes, and a false one for
failure, but that is certainly not true for all of them.

> So in perl:
> 0=false
> 1(or more)=true

It's more complex than that. See above.

> in program return value:
> 0=success
> 1(or error)=error

Not necessarily. On Unix it is generally accepted that a program
returns an exit status of 0 when it considers it has completed
successfully. It returns something else when it considers that it
failed at something. However, this is a convention, and not a rule,
although it is a very, very strong and engrained convention.

> Im asking to make sure that in the case of system(), return value of 0
> (depending on command I'm using)really mean 'success' despite that in perl
> language it means false.

system() returns to you whatever the program's exit status was (with a
bit more information, which is all described in the system() entry in
the perlfunc documentation). If the program's exit status is 0 for
success, then you should check for that. If the program's exit status
is 99, 3 or 56 for success, and 0 or 4 for failure, then you should
check for that. If you have a program like that, however, it may be
hard to sensibly work with it this way. I'd probably fork and exec
explicitly for stuff like that.

system cannot really return anything for success or failure, because
it cannot know what the program deems to be success or failure.

The only time system can return a failure itself, is when it couldn't
find your program at all, or couldn't fork, or something like that.

All of this is thoroughly documented in perlfunc. Have a lok at that
documentation with man or perldoc:

$ man perlfunc
$ perldoc perlfunc
$ perldoc -f system

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.   | again. Then quit; there's no use
NSW, Australia                  | being a damn fool about it.


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

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 V10 Issue 571
**************************************


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