[16986] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4398 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 21 18:06:17 2000

Date: Thu, 21 Sep 2000 15:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969573915-v9-i4398@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 21 Sep 2000     Volume: 9 Number: 4398

Today's topics:
    Re: Ambiguous use of values <bart.lateur@skynet.be>
    Re: Anonymous lists <tim@ipac.caltech.edu>
        best way to compare $var against <DATA> <gorbeast@SPAMSUCKS.subduction.org>
    Re: best way to compare $var against <DATA> <jeff@vpservices.com>
    Re: converting binary string (Martien Verbruggen)
    Re: correction: sorting problem! output should be (a A  <basvg@nomansland.nu>
        deamonize <berube@odyssee.net>
    Re: Find String in Text File - Easy Question <yanick@babyl.sympatico.ca>
    Re: Find String in Text File - Easy Question <lr@hpl.hp.com>
    Re: Find String in Text File - Easy Question (Garry Williams)
    Re: Find String in Text File - Easy Question <westxga@my-deja.com>
        hash array and database inserts <jstone211@my-deja.com>
    Re: How to call a Perlscript ( SSI ) within a Javascrip <gellyfish@gellyfish.com>
    Re: How to Capture Specific Whitespace? beach9000@hotmail.com
        How to detect Windows perl program is already running?? <mkhan@crosscom.com>
    Re: How to mail from somebody besides 'Nobody' in perl <gmiller@nospam_gregmiller.net>
    Re: How to make a child a parent ? <mak@imakhno.freeserve.co.uk>
        image capture from video capture card <tanderse@fsl.noaa.gov>
    Re: ITS BEYOND ME! <bart.lateur@skynet.be>
    Re: More Debugging - Please Help bluearchtop@my-deja.com
    Re: Newbie - averages... <christopher_j@uswest.net>
    Re: Newbie - averages... (Randal L. Schwartz)
    Re: Newbie - averages... <christopher_j@uswest.net>
    Re: Newbie - averages... <bart.lateur@skynet.be>
        Newbie Question rev777_1998@yahoo.com
    Re: Newbie Question <sariq@texas.net>
        newbie subtitution question <ccoffey@nims.wr.usgs.gov>
    Re: newbie subtitution question <UlleAckermann@t-online.de>
    Re: newbie subtitution question <UlleAckermann@t-online.de>
    Re: newbie subtitution question <uri@sysarch.com>
    Re: Parse::RecDescent: Problem with a Grammar (Damian Conway)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Sep 2000 18:35:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Ambiguous use of values
Message-Id: <00lksss093ntjc80bmv0j3q9f2u3c7e5gu@4ax.com>

arthur wrote:

>I put this in a script to try and get a popup menu:
>popup_menu(-name=>'game',
>               -values=>['red','green','blue','chartreuse']),
>and I get this:
># Ambiguous use of values => resolved to "values" =>.
>File 'StarMax HD:Desktop Folder:popup.cgi'; Line 13

You must be using quite an old version of Perl. In 5.004, Perl gave this
warning; in 5.005 (somewhere) and later, this got fixed. Use quites to
prevent it.

	'-values'

># Can't find string terminator "'" anywhere before EOF.
>File 'StarMax HD:Desktop Folder:popup.cgi'; Line 14

Somehow your single quotes aren't balanced. The lines you gave look
fine to me, apart from the fact that they end in a comma. But that is
probably resolved in the surrounding lines...?

-- 
	Bart.


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

Date: Thu, 21 Sep 2000 11:07:45 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Anonymous lists
Message-Id: <39CA4E71.9A58746@ipac.caltech.edu>

akhnaten88@my-deja.com wrote:
> What I needed was a
> function that returns 3 lists, so here (in a nutshell) is what I've
> done:
> 
> sub func() {
> my @a = (1, 2, 3);
> my @b = (2, 3, 4);
> my @c = ('foo', 'bar', 'baz');
> return [\@a, \@b, \@c];
> }

No need to return an array ref of array refs. It's not terrible, but does it
help you somehow? Why not just

return (\@a, \@b, \@c);

or the equivalent

return \(@a, @b, @c)

>I had 2 functions that do this, and
>I had to take the return data from both and merge them into single
>lists. TO avoid writing out the second function, I'll just call then
>above function, func() twice and merge that data.

My way:

@merged = map { @$_ } (func(), func());

your way:

@merged = map { @$_ } (@{func()},@{func()});

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Thu, 21 Sep 2000 13:40:11 -0700
From: Gorbeast <gorbeast@SPAMSUCKS.subduction.org>
Subject: best way to compare $var against <DATA>
Message-Id: <39CA722B.CF988ABD@SPAMSUCKS.subduction.org>

Hello,

I have a script I am working on and theres a part I haven't figured out
yet.  If anybody can help me that would be wonderful.  At one point, my
script should take a variable which is supplied by the user,
$users_newsgroup, and I want it to run against against <DATA>, (which is
a list of newgroups), and return a warning to the user if their
$users_newsgroup does not find a match in <DATA>.  How can I do this?  
Thank you for your time!

G


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

Date: Thu, 21 Sep 2000 14:00:49 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: best way to compare $var against <DATA>
Message-Id: <39CA7701.AAC8D356@vpservices.com>

Gorbeast wrote:
> 
> Hello,
> 
> I have a script I am working on and theres a part I haven't figured out
> yet.  If anybody can help me that would be wonderful.  At one point, my
> script should take a variable which is supplied by the user,
> $users_newsgroup, and I want it to run against against <DATA>, (which is
> a list of newgroups), and return a warning to the user if their
> $users_newsgroup does not find a match in <DATA>.  How can I do this?

my %is_group = map { chomp; $_ => 1 } <DATA>;
&warn() unless $is_group{$users_newsgroup};

-- 
Jeff


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

Date: Thu, 21 Sep 2000 22:03:30 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: converting binary string
Message-Id: <slrn8sl1dc.m9.mgjv@verbruggen.comdyn.com.au>

On 21 Sep 2000 17:53:09 GMT,
	Abigail <abigail@foad.org> wrote:
> Kai Wipplinger (Kai.Wipplinger@de.bosch.com) wrote on MMDLXXVIII
> September MCMXCIII in <URL:news:39CA249D.4B0C95F2@de.bosch.com>:
> :: 
> :: (If EXPR happens to start off
> ::     with 0x, interprets it as a hex string. If EXPR starts off with 0b,
> :: it is interpreted as a binary string.)
> :: 
> :: Perl Version:
> :: This is perl, version 5.005_03 built for MSWin32-x86-object
>                  ^^^^^^^^^^^^^^^^
> 
> It would be a good idea to read the documentation that comes with your
> perl, instead of from random source. Then you won't try to do 5.6.0
> semantics on a 5.005 Perl.

$ pwd
/opt/perl/lib/5.00503/pod
$ grep --context 0b perlfunc.pod

Interprets EXPR as a hex string and returns the corresponding value.
(To convert strings that might start with either 0, 0x, or 0b, see
L</oct>.)  If EXPR is omitted, uses C<$_>.

[--]
Interprets EXPR as an octal string and returns the corresponding
value.  (If EXPR happens to start off with C<0x>, interprets it as a
hex string.  If EXPR starts off with C<0b>, it is interpreted as a
binary string.)  The following will handle decimal, binary, octal, and
hex in the standard Perl or C notation:

The last bit os from the oct() entry.

However:

$ perl -le 'print oct "0b001001"'
9
$ perl5.00503 -le 'print oct "0b001001"'
0

So, it looks like it _is_ documented, but it simply doesn't work.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: Thu, 21 Sep 2000 21:13:32 +0200
From: B. van Gaalen <basvg@nomansland.nu>
Subject: Re: correction: sorting problem! output should be (a A Aa AA AaA AAa  AAA).
Message-Id: <hcnkssopecq57i1uni2rvmduk87l82ipq9@4ax.com>

I just gotta say: thanks for this message!
I was trying to figure out a way to sort un casesensative.
This helpt a lot! :)

Regards,
Bas

On Wed, 09 Aug 2000 16:13:23 +0200, Erik van der Knaap
<eknaap@lucent.com> wrote:

 ...

>>    sort { lc $a cmp lc $b or $a cmp $b } @unsorted;
>yep, I want something like this. (I will use this because the output looks better now).
>
>> 

 ...



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

Date: Thu, 21 Sep 2000 15:03:42 -0400
From: "Neb" <berube@odyssee.net>
Subject: deamonize
Message-Id: <8_sy5.226$hs2.10675@news.globetrotter.net>

hi,

I got some problem deamonizing a process (child become dissociated from
parent) on Unix.  I read "perlipc" and I wrote to this news group but I
can't make it work yet.

Here is the code:
---------------------------------
use POSIX "setsid";

my $pid = fork;

if( $pid == 0 )
{
    if( setsid() == -1 )
    {
        print 'Process error.';
    }
    sleep(40);
    print "child";
    exit(0);
}
elsif( undef $pid )
{
     print 'Process error.';
}
else
{
      print 'Parent process.';
}
---------------------------------

The problem with this code: the parent process *still waits* for the child
process to complete.  But I want the parent process to exit, and the child
process to continue to live!

What is wrong with my code?

thanks for the help,

neb







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

Date: Thu, 21 Sep 2000 18:03:57 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Find String in Text File - Easy Question
Message-Id: <h4sy5.4149$vZ.243935@news20.bellglobal.com>

pgodkin@my-deja.com wrote:
: I confess that I have little perl experience. I want to find the number
: of occurences of a multi-word text string in a text file.

: $text_string = "THIS IS A TEST";
: open(LOGFILE, "/../mytext_file.txt");
: @lines = grep /"$text_string"/,readline LOGFILE;
                 ^------------^------ no need for quotes here
: $count = @lines;
: print $count;  **** ALWAYS PRINTS ZERO
: close(LOGFILE);

Another way of doing it:

open LOGFILE, "whatever.txt" or die "Coun't open file: $!\n";
/$text_string/ and $count++ while <LOGFILE>;
print $count;

Or if you want a one-liner:

perl -ne'INIT{$t=shift}$c+=/$t/}{print$c' regex logfile

(only a slight variation on Abigail's infamous signature)

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Thu, 21 Sep 2000 11:28:43 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Find String in Text File - Easy Question
Message-Id: <MPG.1433f332fb187e498ada9@nntp.hpl.hp.com>

In article <8qdfoe$7g5$1@nnrp1.deja.com> on Thu, 21 Sep 2000 17:16:20 
GMT, pgodkin@my-deja.com <pgodkin@my-deja.com> says...
> I confess that I have little perl experience. I want to find the number
> of occurences of a multi-word text string in a text file.

Start out by using the following at the beginning of every Perl program:

    #!/path/to/your/perl -w
    use strict;

> $text_string = "THIS IS A TEST";

Then you will have to use 'my' ahead of $text_string in the above.

> open(LOGFILE, "/../mytext_file.txt");

That is a strange-looking path.  Is the file really in the root 
directory?

How do you know the file opened successfully?

  open LOGFILE, "/../mytext_file.txt" or
      die "Couldn't open '/../mytext_file.txt'. $!\n";

> @lines = grep /"$text_string"/,readline LOGFILE;

The real problem is above.  You have introduced literal double-quotes 
into the pattern to be matched.  Take them out and everything should 
work as you have shown it.

It would be more usual to write that line this way:

  my @lines = grep /$text_string/, <LOGFILE>;

> $count = @lines;

But perhaps you don't know that you could have written simply:

  my $count = grep /$text_string/, <LOGFILE>;

Read the documentation on the grep() function:  `perldoc -f grep`

Note that this gives the number of input lines on which the match 
occurs, not the total number of matches if there can be more than one 
per line.

> print $count;  **** ALWAYS PRINTS ZERO
> close(LOGFILE);

This approach reads the entire file into memory at once, then searches 
it.  If the file is very large, one line at a time would be much better:

  my $count;
  /$text_string/o and $count++ while <LOGFILE>;

The /o modifier is to prevent the regex from being compiled for every 
input line.  As you are looking for a simple match, without needing any 
regular-expression features, the best way is to use the index() 
function:

  index($_, $text_string) >= 0 and $count++ while <LOGFILE>;

A long answer for an 'easy question', eh?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 21 Sep 2000 18:40:33 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Find String in Text File - Easy Question
Message-Id: <BCsy5.682$fa2.53851@eagle.america.net>

On Thu, 21 Sep 2000 17:16:20 GMT, pgodkin@my-deja.com 
  <pgodkin@my-deja.com> wrote:
>I confess that I have little perl experience. I want to find the number
>of occurences of a multi-word text string in a text file.
>
>$text_string = "THIS IS A TEST";
>open(LOGFILE, "/../mytext_file.txt");

You should check the success of the open().  (I suspect that it failed
owing to the path.)  

	open(LOGFILE, "/../mytext_file.txt")
	  || die "can't open /../mytext_file.txt: $!";

>@lines = grep /"$text_string"/,readline LOGFILE;

There is no need to quote $text_string.  Frome perldoc perlfunc: 

    readline EXPR
    Reads from the filehandle whose typeglob is contained in EXPR.
                                    ^^^^^^^^

leads me to believe that you should have said `readline *LOGFILE'.
But why not just 

	@lines = grep /$text_string/, <LOGFILE>;

>$count = @lines;
>print $count;  **** ALWAYS PRINTS ZERO
>close(LOGFILE);

Hmmm.  Maybe just

	grep -c pattern filename

-- 
Garry Williams


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

Date: Thu, 21 Sep 2000 20:19:12 GMT
From: Glenn West <westxga@my-deja.com>
Subject: Re: Find String in Text File - Easy Question
Message-Id: <8qdqf8$lb8$1@nnrp1.deja.com>

In article <8qdfoe$7g5$1@nnrp1.deja.com>,
  pgodkin@my-deja.com wrote:
> I confess that I have little perl experience. I want to find the
number
> of occurences of a multi-word text string in a text file.
>
> $text_string = "THIS IS A TEST";
> open(LOGFILE, "/../mytext_file.txt");
> @lines = grep /"$text_string"/,readline LOGFILE;

$cnt=grep /$text_string/, <LOGFILE>;
print "$cnt\n";

> $count = @lines;
> print $count;  **** ALWAYS PRINTS ZERO
> close(LOGFILE);
>


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


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

Date: Thu, 21 Sep 2000 21:06:35 GMT
From: J. Stone <jstone211@my-deja.com>
Subject: hash array and database inserts
Message-Id: <8qdt87$osa$1@nnrp1.deja.com>

I have a hash array with various key values:

$hash{key1}[$count];
 .
 .
 .
$hash{key50}[$count];

I have 50 keys that correlate to a field in a Sybase table.  I need to
make sure the correct hash element for a particular key gets inserted
into the proper field.  Since I have so many items to work with I
wanted to know if anyone has any tips to make this task easier.

Thanks,
Julia


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


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

Date: 21 Sep 2000 07:38:34 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to call a Perlscript ( SSI ) within a Javascript ?
Message-Id: <8qcada$m3v$1@orpheus.gellyfish.com>

On Wed, 20 Sep 2000 20:28:38 +0200 dplanet wrote:
> Hi
> can anybody help me ? I would like to call a Perlscript, exactly
> a Server Site Include within a Javascript. The Perlscript is
> running on a web server. How can i do that. I tried with following code
> without success !  What is wrong ?
> 
> <html>
> <head>
> <script language="JavaScript">
> function test () {
> document.write("<!-- #exec cgi='cgi-bin/test3.pl' -->");
> }
> </script>
> </head>
> <body>
> <script>
> test();
> </script>
> </body>
> </html>
> 
> The Perlscript is not called !!  Why  ??
> 

Because by the time the *Client Side* Javascript runs it is way too late
for the *Server Side Includes* to have any affect.  I would recommend that
you go and discuss this is comp.lang.javascript as this has nothing
whatsoever to with Perl.

Followups set.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Thu, 21 Sep 2000 19:50:49 GMT
From: beach9000@hotmail.com
Subject: Re: How to Capture Specific Whitespace?
Message-Id: <8qdoqg$j3t$1@nnrp1.deja.com>

Thanks for all your help,

But here's one more case that I'm curious about: how would you capture
the whitespace before EACH instance of the markertext on the SAME line?

For instance:

[sol]   markertext blah     markertext blah [...] blahmarkertext[eol]

so that

   markertext 1 = 3
   markertext 2 = 5
   ...
   markertext n = 0

where markertext is the same keyword found throughout the line.

My first guess would be to use previous posted split example, and try to
figure out the index of the markertext.  After that, I could just grab
the space in the preceding cell, but I'd like to here other suggestions.

Thanks


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


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

Date: Thu, 21 Sep 2000 16:03:56 -0500
From: "Mohammad Khan" <mkhan@crosscom.com>
Subject: How to detect Windows perl program is already running??????????????????
Message-Id: <39ca78ed$0$6821@wodc7nh1.news.uu.net>


Hi,
    I have a windows perl program which tries to determine if another copy
of the same program is running, and if it's already running then terminate,
by using the following method.

    When the program is run first time, it checks for cmsip.pid file and if
it doesn't exist creates the file and never closes it, so that if 2nd
instance of this program is run, it checks for the file, finds it there and
tries to remove the file. The 2nd instance will not be able to remove the
file, since the first instance is still running and never closed the file
handler. So the 2nd isntance will quit based on its unablity to remove the
file.

    However if the first program has terminated, 2nd instance will remove
the file and recreate it and never closes it. Now this perl porgram will run
forever, unless the DOS windows it's running in is closed or terminated by
Ctrl-C.

    Now the above approach works in theory only, becuase when the 1st
instance creates the cmsip.pid, 2nd isntance of program is unable to delete
the file, which is fine. But if the 1st instance quits and 2nd instance is
started, 2nd instance is still unable to remove the file and terminate
assuming 1st instance of program is still runnning, when it's not.


    Now I am able to delete the file from Windows Explorer,
even when the 1st instance is running, which is strange. If
I have a c program which opens a file and don't close the
file handler, I will be unable to delete the file from
Windows Explorer, saying "Access denied", so I am
confused how the Windows Exploere is able to delete the
file when the perl program has never closed the file.

    I will appreciate if somebody can find out the problem with my code
listed below or show me show other solution to this problem.

    I always get 0 for unlink function call, does it indicate problems and
if yes how do I find the cause of the problem.


$pfile = "cmsip.pid";

   if (open(FILE, $pfile) == 0)
   {
      printf("$pfile file doesn't exist.\n");
      if (open(FILE, ">>$pfile") == 0)
      {
         printf("Unable to create $pfile file.\n");
         exit(0);
      }

   }
   else
   {
      printf("$pfile filedoes exist.\n");
      $l_chk = unlink("cmsip.pid");

      if ( -e $pfile)


           printf("$pfile couldn't be removed.\n");
           exit(0);
      }  # if (-e $pfile)
      else


           printf("$pfile removed.\n");
      }  # if (-e $pfile)

      printf("l_chk = $l_chk.\n");

   }



Thanks.






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

Date: Thu, 21 Sep 2000 15:21:47 -0400
From: Greg Miller <gmiller@nospam_gregmiller.net>
Subject: Re: How to mail from somebody besides 'Nobody' in perl
Message-Id: <3gnksssrb3e4q7tq6i2b7s6itsp675g0e3@4ax.com>

	Some systems don't let you change the from address (it's an
option in Sendmail).  Additionally, the code you posted may not be
secure, you need to validate that $recipient doesn't contain anything
malicious.  A better, more standardized, way is to use sendmail:

$mailprog="/usr/lib/sendmail -t";
if(!open(M,"|$mailprog)){die;}
print M "From: Me@myserver.com\n";
print M "To: $recipient\n";
print M "Subject: whatever\n";
print M "\n";
print M "Message body\n";
close(M);

----
Greg Miller (gmiller@gregmiller.net)
http://www.customprogrammer.com
http://www.gregmiller.net
http://www.net-chess.com




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

Date: Thu, 21 Sep 2000 19:44:58 +0100
From: "Makhno" <mak@imakhno.freeserve.co.uk>
Subject: Re: How to make a child a parent ?
Message-Id: <8qdkuh$6mq$1@newsg1.svr.pol.co.uk>

>> >     system('notepad');

>well i'm coding on Windows, but the actual Perl code will run on Unix.

In that case, consider doing:

system("notepad &");

Though of course, 'notepad' might not be what you want.




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

Date: Thu, 21 Sep 2000 13:46:22 -0600
From: "Travis" <tanderse@fsl.noaa.gov>
Subject: image capture from video capture card
Message-Id: <8qdoie$8mr$1@peabody.colorado.edu>

Hi,

Does someone know of a way to capture an image from a webcam or video
capture card using Perl and Windows 98?

Thank you.






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

Date: Thu, 21 Sep 2000 21:34:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: ITS BEYOND ME!
Message-Id: <6mukss0rdf0fvt1lnj6o8sr5her1ddtohj@4ax.com>

Chris Saunders wrote:

>My problem: I have tried to create a form for the first time.  Done it ok,
>and downloaded a perl script that seems to have the features I need (judging
>by the descriptions), but its readme talks about server cgi_bins and so
>forth.
>
>WTF? Is it referring to a Unix machine, in which case I know nothing about
>it.

No. It is referring to server configuration specific behaviour. The
server may be configured to allow only running CGI scripts if they are
in a specific directory. "cgi-bin" is the most common name for that
directory.

It depends on the ISP. You should first consult their FAQ (sometimes
called "help"; check the home page for your ISP domain), try to install
a very simple example script (maybe your ISP even makes some of those
available), and see if you can get it to run *unaltered*. Only then
start messing with other scripts. If you can't find the answer you need
in their FAQ, you can still ask them. We don't know. We *can't* know.

Also look at the "idiot's guid to CGI" page on <www.perl.com>:

	http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html


And I think that for this kind of stuff, you're better off adressing a
CGI specific newsgroup: <news:comp.infosystems.www.authoring.cgi>, which
is automoderated. Just look at few messages to know what to do.

-- 
	Bart.


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

Date: Thu, 21 Sep 2000 18:59:20 GMT
From: bluearchtop@my-deja.com
Subject: Re: More Debugging - Please Help
Message-Id: <8qdlpq$f8o$1@nnrp1.deja.com>

Actually, I still do have the problem. I thought statically linking dbm
fixed it, but it didn't.

The platform is SunOS 5.6.

Here's a simple script that shows my problem:

#!/usr/local/bin/perl5.005
use DB_File;
dbmopen (%DB,"test.db",0700);
$DB{test} = "test";
dbmclose %DB;
undef %DB;
dbmopen (%DB,"test.db",0700);
print $DB{test};
print "\n\n";

### THIS CORRECTLY CREATES THE test.db AND PRINTS "test"

Now, I try to read it with 5.6

#!/usr/local/bin/perl5.6.0
use DB_File;
dbmopen (%DB,"test.db",0700);
print $DB{test};
print "\n\n";


## THIS PRINTS NOTHING!! ##

Any ideas? How can I tell what version DB_File I have?
Thanks



> I did more debugging of my stuff (I didn't write it), and I found
> that I am failing to open the gdbm file on the silicon graphics
> machine.  It works fine on the solaris box.  Now I'm really curious
> about the architecture that BLUEARCHTOP is using.
>
> Sarah
> officers@aries.tucson.saic.com
>
> Sarah Officer wrote:
> >
> > Help!  We have upgraded to 5.6.0 from 00502, and I find that our
> > GDBM_FIle hashes (using the Tie::Hash stuff) work on Solaris but not
> > on our Silicon Graphics machines.  Bluearchtop: what platform are
> > you using?  We have gdbm 1.8.0.
> >
> > The error message I get is:
> >
> > "Can't call method "FETCH" on an undefined value at
> > /ATMS/Scripts/gdbm.pl line 23."
> >
> > The line in question is $ref->FETCH line.  Any ideas of why this
> > would work on a Sun (Solaris 2.8) and not Silicon Graphics (IRIX6.5)
> > would be appreciates.  Maybe bluearchtop & I are having the same
> > problem?
> >
> > sub FETCH{
> >     my $self = shift ;
> >     my $ref = $self->{'gdbm'};
> >     $ref->FETCH(@_) ;
> > }
> >
> > Thanks,
> >
> > Sarah
> > officers@aries.tucson.saic.com
> >
>


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


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

Date: Thu, 21 Sep 2000 14:04:21 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Newbie - averages...
Message-Id: <gJuy5.3324$kY3.251797@news.uswest.net>

# sans Perl magic mojo (mostly):

sub average()
    {
    my $sum, $n;
    foreach (@_)
        { $sum += $_; $n++; }
    return $sum / $n;
    }


# Then,

my $file, @file;
open (FILE, "<file.blah");
    {
    local $/ = '';
    $file = <FILE>;
    }
close (FILE};

@file = split(/\n/, $file);
chomp @file;

my $average = average(@file);




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

Date: 21 Sep 2000 14:06:47 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Newbie - averages...
Message-Id: <m1n1h11ml4.fsf@halfdome.holdit.com>

>>>>> "Christopher" == Christopher M Jones <christopher_j@uswest.net> writes:

Christopher>     my $sum, $n;

This almost certainly doesn't mean what you probably think it means.
You're making a local variable $sum, and then just casually mentioning
another global variable $n for no apparent reason.

Perhaps you wanted:

        my ($sum, $n);

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 21 Sep 2000 14:24:26 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Newbie - averages...
Message-Id: <90vy5.3443$kY3.258840@news.uswest.net>


"Randal L. Schwartz" <merlyn@stonehenge.com> wrote:
> >>>>> "Christopher" == Christopher M Jones <christopher_j@uswest.net>
writes:
>
> Christopher>     my $sum, $n;
>
> This almost certainly doesn't mean what you probably think it means.
> You're making a local variable $sum, and then just casually mentioning
> another global variable $n for no apparent reason.
>
> Perhaps you wanted:
>
>         my ($sum, $n);

Oops, my bad, yeah definitely want 'my ($sum, $n)'.




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

Date: Thu, 21 Sep 2000 21:50:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Newbie - averages...
Message-Id: <5f0lssont2cfmqnug556jn6t95n21668ar@4ax.com>

ian_tait@my-deja.com wrote:

>What I'm trying to do is to open a text file (I
>can do this bit :-) that contains a column of
>numbers eg,
>
>33
>33
>44
>55
>
>and sum them, then to get an average of the
>numbers, divide by the number of numbers present
>(which changes).

 sub sum {
     my $sum = shift || 0;
     $sum += $_ foreach @_;
     $sum;
 }
 sub average {
     sum(@_)/@_;
 }
 print average(grep { /\d/ } <DATA>);
# Trailing newlines don't hurt.
__DATA__
33
33
44
55
	    
-- 
	Bart.


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

Date: Thu, 21 Sep 2000 18:26:11 GMT
From: rev777_1998@yahoo.com
Subject: Newbie Question
Message-Id: <8qdjr9$cnf$1@nnrp1.deja.com>

Hello,
I am looking for a script that writes the parameters from a form
submission to a html file rather than the stdout user.  Is there such a
script out there?  Possibly some of you gurus have a code sample and
explanation...

I am new to Perl but not new to programming.

Thanks,
Rev


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


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

Date: Thu, 21 Sep 2000 18:42:15 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: Newbie Question
Message-Id: <39CA5686.81B8404@texas.net>

rev777_1998@yahoo.com wrote:
> 
> Hello,
> I am looking for a script that writes the parameters from a form
> submission to a html file rather than the stdout user.

What's "the stdout user"?

perldoc CGI
perldoc perlopentut

- Tom


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

Date: Thu, 21 Sep 2000 18:59:24 GMT
From: Chris Coffey <ccoffey@nims.wr.usgs.gov>
Subject: newbie subtitution question
Message-Id: <Pine.LNX.4.10.10009211157140.31763-100000@nims.wr.usgs.gov>

How come this doesn't work correctly?

#!/usr/bin/perl -wi.bak

$old = $ARGV[0];
$new = $ARGV[1];
$file = $ARGV[2];

open(IN, ">$file") || die "can't open $file: $!";

while(<IN>) {
  s/$old/$new/g;
}

close(IN) || die "can't close $file: $!";


Whenever I run the script, the contents of the file is deleted.  Thanks
for your help.

Chris




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

Date: Thu, 21 Sep 2000 21:47:41 +0200
From: Ulrich Ackermann <UlleAckermann@t-online.de>
Subject: Re: newbie subtitution question
Message-Id: <39CA65DD.69C25BC0@t-online.de>

Chris Coffey wrote:
> 
> How come this doesn't work correctly?
> 
> #!/usr/bin/perl -wi.bak
> 
> $old = $ARGV[0];
> $new = $ARGV[1];
> $file = $ARGV[2];
> 
> open(IN, ">$file") || die "can't open $file: $!";
You should open this file for reading and another one for writing. You
cannot open a file for both afaik.
open IN, $file || die ...
open OUT, "$file.out" || die ...

> while(<IN>) {
>   s/$old/$new/g;
print OUT $_;

> close(IN) || die "can't close $file: $!";
Perl does this for you.


HTH, Ulrich



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

Date: Thu, 21 Sep 2000 21:51:20 +0200
From: Ulrich Ackermann <UlleAckermann@t-online.de>
Subject: Re: newbie subtitution question
Message-Id: <39CA66B8.5FFD60BD@t-online.de>

Ulrich Ackermann wrote:
> 
> You should open this file for reading and another one for writing. You
> cannot open a file for both afaik.
> open IN, $file || die ...
> open OUT, "$file.out" || die ...

Of course this must be:
open OUT, ">$file.out" || die ...
          ^^^

Sorry,  Ulrich


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

Date: Thu, 21 Sep 2000 20:05:59 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: newbie subtitution question
Message-Id: <x7hf79cxy1.fsf@home.sysarch.com>

>>>>> "UA" == Ulrich Ackermann <UlleAckermann@t-online.de> writes:

  UA> open IN, $file || die ...
  UA> open OUT, "$file.out" || die ...

besides the > problem you fixed later, both of those will either need
parens for the open call or use 'or' instead of ||.

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: 21 Sep 2000 18:12:25 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Parse::RecDescent: Problem with a Grammar
Message-Id: <8qdj1v$uug$1@towncrier.cc.monash.edu.au>

"Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk> writes:

>BTW Damian, while I've got your attention, any chance of
>explaining why <rulevar> seems to require a local before the
>variable name - this isn't documented AFAICS, and it seems
>to conflict with the docs in the sense that they say rulevars turn
>into lexicals. What's the deal.

The deal is that if you say:

	somerule: <rulevar: $x>

you get a lexical $x within the rule (only). If you say:

	somerule: <rulevar: local $y>

you get a localized $y within the rule (and any subrules it calls).

I'll extend the documentation on <rulevar> to make this distinction
clearer.

Damian


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4398
**************************************


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