[22546] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4767 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 27 18:16:09 2003

Date: Thu, 27 Mar 2003 15:15:35 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Mar 2003     Volume: 10 Number: 4767

Today's topics:
    Re: declaring vars & values from a file <tore@aursand.no>
    Re: declaring vars & values from a file <tzz@lifelogs.com>
    Re: declaring vars & values from a file <goldbb2@earthlink.net>
        Detecting WAP 1.1/1.2/2.0 compatibility (Clyde Ellul)
    Re: Detecting WAP 1.1/1.2/2.0 compatibility <koch@w3development.de>
    Re: doubts on \n <goldbb2@earthlink.net>
    Re: doubts on \n ctcgag@hotmail.com
        Faster file comparison? <amperry@provide.net>
    Re: Faster file comparison? <ndronen@io.frii.com>
    Re: Faster file comparison? <jurgenex@hotmail.com>
    Re: Faster file comparison? <goldbb2@earthlink.net>
    Re: Faster file comparison? <goldbb2@earthlink.net>
    Re: Faster file comparison? <amperry@provide.net>
        global variables with CGI <mfield@ernie.botany.ubc.ca>
    Re: global variables with CGI <tore@aursand.no>
    Re: global variables with CGI <bwalton@rochester.rr.com>
        how to call one program through another program and cap (ramesh)
    Re: how to call one program through another program and <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: how to call one program through another program and <jurgenex@hotmail.com>
    Re: how to call one program through another program and <barryk2@SPAM-KILLER.mts.net>
        How to determine file creation time (Steve)
    Re: How to determine file creation time <Andrew.McGregor@amtrak.co.uk>
    Re: How to determine file creation time <Andrew.McGregor@amtrak.co.uk>
    Re: How to determine file creation time (Randal L. Schwartz)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Mar 2003 18:38:51 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: declaring vars & values from a file
Message-Id: <pan.2003.03.26.17.38.43.658974@aursand.no>

On Wed, 26 Mar 2003 13:30:44 +0000, tim wrote:
> I have a text file which contains variable names and values, ie:
> 
> var1=hello
> var2=/home/root
> var3=test

You should take a look at the Config::*-modules found at CPAN [1],
especially Config::IniFiles.

If you _must_ do it "manually", then you should store the data in a hash
rather than using symbolic references;

  my %config = ();
  open( CONFIG, "config.cfg" ) or die "Couldn't open file; $!\n";
  while ( <CONFIG> ) {
      chomp;
      next unless ( m,=, ); # Skip lines with a '=' in it
      s,^\s+,,; # Remove leading spaces
      s,\s+$,,; # Remove trailing spaces
      my ($ident, $value) = split( /\s*=\s*/, $_, 2 );
      if ( length($ident) && length($value) ) {
          $config{$ident} = $value;
      }
  }
  close( CONFIG );


[1] http://www.cpan.org/


-- 
Tore Aursand


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

Date: Wed, 26 Mar 2003 14:42:07 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: declaring vars & values from a file
Message-Id: <4nd6kdgbjk.fsf@lockgroove.bwh.harvard.edu>

On Wed, 26 Mar 2003, tim@deadgoodsolutions.spam-me-and-die.com wrote:
> I have a text file which contains variable names and values, ie:
> 
> var1=hello
> var2=/home/root
> var3=test
> 
> I want to read this file in and declare each variable and at the
> same time give it that value, i have this code which seems to work,

Your code uses symbolic references.  Does that mean you don't know the
variable names before you load your settings?  What use are those
variables if you don't know their names?

Look at the AppConfig module on CPAN, it will probably do what you
want, and a lot more.

Ted


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

Date: Wed, 26 Mar 2003 23:09:55 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: declaring vars & values from a file
Message-Id: <3E827993.3C7DD05A@earthlink.net>

tim wrote:
[snip]
> $inipath="/home/tim/settings";
> open (INFILE, "$inipath")||die "Cannot open $inipath for reading";

Some simple code for reading the ini file format is as follows:

   use strict;
   use warnings;
   open(my($inifile), "<", "/home/tim/settings")
      or die "Couldn't open settings: $!";
   my ($key, %inifile);
   while( <$inifile> ) {
      $key = $1, next if /^\[(.*)\]$/;
      next unless defined $key and /(.*?)=(.*)/;
      $inifile{$key}{$1} = $2;
   }
   close($inifile);

Then, to use this data:

   my $x = $inifile{"section name"}{var1};

Or perhaps:
   my $section = $inifile{"section name"};
   my @vars = @{$section}{"var1".."var3"};


-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 27 Mar 2003 07:19:09 -0800
From: cellul@msn.com (Clyde Ellul)
Subject: Detecting WAP 1.1/1.2/2.0 compatibility
Message-Id: <fd078454.0303270719.7a22ffcc@posting.google.com>

Hi guys,

Is there a simple way of detecting what WAP version a phone browser
supports?

I am writing a phone directory application for WAP and I need to
automatically detect the user's browser compatibility, specifically
whether it is WAP 1.1/1.2 or 2.0-compliant.

One reason why I want to do this is to know which WTAI functions the
browser supports. For example, WAP 1.1 support only the function to
dial a number, while 1.2 and above support other functions such as
storing a number into the user's phonebook.

I have tried using the HTTP_USER_AGENT and HTTP_ACCEPT http variables
with the Nokia 6210, Siemens S45 and the Nokia 7650. However,
HTTP_USER_AGENT only lists the brand and version of the phone and
browser; it does not say what type of WAP specification it supports.
HTTP_ACCEPT, on the other hand, lists all the MIME types that the
phone supports, but once again there is no clear indication as to what
WAP spec the phone supports.

Am I on the right track? What should I look for within these strings?
Is there any other way of finding out the WAP version?

Of course, I could always find out which browsers support what, keep a
table of browser to WAP version mappings and then send the appropriate
WML as necessary... But this is a high maintenance solution I would
like to avoid.

Thanks in advance for your help.

Cheers,
Clyde


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

Date: Thu, 27 Mar 2003 19:03:06 +0100
From: Johannes Koch <koch@w3development.de>
Subject: Re: Detecting WAP 1.1/1.2/2.0 compatibility
Message-Id: <b5vffd$7c6i$1@ID-61067.news.dfncis.de>

Clyde Ellul wrote:
[WAP version support in browser]

> I have tried using the HTTP_USER_AGENT and HTTP_ACCEPT http variables
> with the Nokia 6210, Siemens S45 and the Nokia 7650. However,
> HTTP_USER_AGENT only lists the brand and version of the phone and
> browser; it does not say what type of WAP specification it supports.
> HTTP_ACCEPT, on the other hand, lists all the MIME types that the
> phone supports, but once again there is no clear indication as to what
> WAP spec the phone supports.

HTTP User-Agent and Accept headers provode only for limited information 
on browser capabilities. This is where UAProf comes into play. UAProf is 
a WAPForum (now OMA) specification which defines a profile with 
capabilities. Have a look at the specification. Some of the new phones 
by Nokia, SonyEricsson etc. provide a link to a profile in an HTTP header.

You may also have a look at the DELI project, a Java implementation for 
CC/PP- and UAProf-based profile resolution. I have a list of some UAProf 
profiles at <http://w3development.de/rdf/uaprof_repository/>

f'up2 c.t.x
-- 
Johannes Koch
In te domine speravi; non confundar in aeternum.
                           (Te Deum, 4th century)



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

Date: Wed, 26 Mar 2003 23:16:51 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: doubts on \n
Message-Id: <3E827B33.9518D345@earthlink.net>

Xavier Noria wrote:
[snip]
> Maybe there is room here for a module. It would figure out the
> convention in a given text file regardless of the platform and
> transparently do the right thing when reading or writing.

If the text file follows the convention of the platform that it's on,
then there's no need for any such thing.

It's only because Xho is reading Windows files while running Linux that
the problem comes up for him (her?).

> I don't use Windows but I guess if I had to write scripts under Cygwin
> configured with Unix newlines I would like that robustness.

IIRC, you can tell Cygwin to make it so that reading a Windows file
(from certain directories/drives, or possibly based on file extention)
results in the \015s not appearing in your input (as if you'd opened it
under Windows in text mode).

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 27 Mar 2003 16:56:22 GMT
From: ctcgag@hotmail.com
Subject: Re: doubts on \n
Message-Id: <20030327115622.922$1l@newsreader.com>

toddrw69@excite.com (trwww) wrote:
>
> The default setting for $/ is portable between Linux and Windows.

Portable in the sense that the program can be moved between the platforms,
not in the sense that the text files can be moved between the platforms.

> When
> reading from and writing to files in Windows, your program never needs
> to think about the \015 because the OS handles it.

Really, I think it is something in the perl guts that handles it,
not the OS, isn't it?

>
> When you say:
>
> print FH "foo bar\n";
>
> the OS will stick the \015 into the stream for you. Same with reading.
> When you say:
>
> $string = <FH>;
>
> there is no \015 in the string

On Windows

> because the OS stripped it out for you
> ( unless FH has been binmode()ed ).

On linux, the \015 isn't stripped out.  Yes, I know on linux it
wouldn't add the \015 in the first place, but on windows it does.
For example, someone saves as a CSV from Excel, then I read the file
into perl on Linux,  I have \015 that I don't want.

Since Perl is the glue that holds the informatics world together,
this is not an unusual situation.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Thu, 27 Mar 2003 04:06:36 GMT
From: Michael Perry <amperry@provide.net>
Subject: Faster file comparison?
Message-Id: <gNuga.21411$pK4.1885353@newsread1.prod.itd.earthlink.net>

Anyone know how this might be made faster? I'm trying to remove identical 
binary files with different names. This works, but is impractically slow:

#!/usr/bin/perl -w

use strict;

my @contents = glob("*");
my $i;
my $j;

for ($i = 0; $i < @contents; $i++) {
        for ($j = ($i+1); $j < @contents; $j++) {
                if (system("cmp $contents[$i] $contents[$j]")=='')
                        {unlink($contents[$j])}
        }
}

--I suspect it's because I'm using the external "cmp" there, but I don't 
know of a native perl substitute. (And yes, I tried writing this w/o the 
C-style "for" loop, but it didn't seem to work at all then.)

Thanks in advance,
--AMP
-- 
Brain for sale. Hardly used.


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

Date: 27 Mar 2003 04:28:53 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: Faster file comparison?
Message-Id: <3e827e05$0$197$75868355@news.frii.net>

Michael Perry <amperry@provide.net> wrote:
MP> Anyone know how this might be made faster? I'm trying to remove identical 
MP> binary files with different names. This works, but is impractically slow:

MP> #!/usr/bin/perl -w

MP> use strict;

MP> my @contents = glob("*");
MP> my $i;
MP> my $j;

MP> for ($i = 0; $i < @contents; $i++) {
MP>         for ($j = ($i+1); $j < @contents; $j++) {
MP>                 if (system("cmp $contents[$i] $contents[$j]")=='')
MP>                         {unlink($contents[$j])}
MP>         }
MP> }

MP> --I suspect it's because I'm using the external "cmp" there, but I don't 
MP> know of a native perl substitute. (And yes, I tried writing this w/o the 
MP> C-style "for" loop, but it didn't seem to work at all then.)

I hope you're not doing this in /usr/bin, where not a few files are
hardlinks, having different names and behaving differently depending
on the contents of argv[0].

Regards,

Nicholas

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


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

Date: Thu, 27 Mar 2003 05:22:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Faster file comparison?
Message-Id: <4Uvga.110288$iq1.106529@nwrddc02.gnilink.net>

Michael Perry wrote:
> Anyone know how this might be made faster? I'm trying to remove
> identical binary files with different names. This works, but is
> impractically slow:
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my @contents = glob("*");
> my $i;
> my $j;
>
> for ($i = 0; $i < @contents; $i++) {
>         for ($j = ($i+1); $j < @contents; $j++) {
>                 if (system("cmp $contents[$i] $contents[$j]")=='')
>                         {unlink($contents[$j])}

Here you will get into trouble. Because you are unlinking $content[$j]
effectively you are deleting a file which in a future incarnation of the
outer loop will be accessed as $content[$i] again but doesn't exit any more.
You need to remove that entry from the array @content, too.

>         }
> }
>
> --I suspect it's because I'm using the external "cmp" there, but I
> don't know of a native perl substitute. (And yes, I tried writing
> this w/o the C-style "for" loop, but it didn't seem to work at all
> then.)

I would rather think that the nested loop is killing your performance, at
least when looking at many files. You got an O(n^2) algorithm here.

It might be faster if you compute a checksum for each file. This can be done
in O(n).
And then just compare those files, which have identical checksums. This will
reduce your n dramatically.

Or just use the file size as the checksum. It is easy and very fast to
compute.

jue




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

Date: Thu, 27 Mar 2003 01:12:16 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Faster file comparison?
Message-Id: <3E829640.5FE23C01@earthlink.net>

Michael Perry wrote:
> 
> Anyone know how this might be made faster? I'm trying to remove
> identical binary files with different names. This works, but is
> impractically slow:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my @contents = glob("*");
> my $i;
> my $j;
> 
> for ($i = 0; $i < @contents; $i++) {
>         for ($j = ($i+1); $j < @contents; $j++) {
>                 if (system("cmp $contents[$i] $contents[$j]")=='')
>                         {unlink($contents[$j])}
>         }
> }

use strict;
use Digest::MD5;
use File::Compare;

my @sizegroups = do {
   my %x;
   -r && -f _ && push @{ $x{-s _} }, $_ for glob("*");
   grep @$_ > 1, values %x;
};
my ($md, @nextpass);
foreach my $names (@sizegroups) {
   if( @$names == 2 ) {
      push @nexpass, $names;
      next;
   }
   $md ||= Digest::MD5->new;
   my %bymd;
   for my $name (@$names) {
      open( my ($fh), "<", $name )
         or warn("Couldn't open $name: $!"), next;
      binmode $fh;
      push @{ $bymd{$md->addfile($fh)->digest} }, $name;
   }
   push @nextpass, grep @$_ > 1, values %bymd;
}
my $names = shift @nextpass;
while( @$names > 2 or $names = shift @nextpass ) {
   my $a = shift @$names;
   open( my ($afh), "<", $a )
      or warn("Couldn't open $a for reading: $!"), next;
   binmode($afh);
   my @unlink;
   for my $j ( reverse 0 .. $#$names ) {
      my $b = $names->[$j];
      seek( $afh, 0, 0 );
      if( open( my ($bfh), "<", $b ) ) {
         if( compare($afh, $bfh) == 0 ) {
            print "WOW!\n";
            print "Two files ($a, $b) with the same MD5 digest,\n";
            print "but which are unequal!\n";
            print "Isn't there a prize for this?\n";
            next;
         }
         push @unlink, $b;
      } else {
         warn "Error opening $b: $!";
      }
      splice @$names, $j, 1;
   }
   next unless @unlink;
   close($afh);
   my %fail;
   unlink $_ or push @{$fail{$!}}, $_ for @unlink;
   unlink $a or push @{$fail{$!}}, $a if %fail;
   while( my ($err, $files) = each %fail ) {
      warn "Couldn't unlink [@$files]: $err\n";
   }
}
__END__
[untested]

First, group files by size.  We only need to compare files to others
with the same size.

Then, for each group, calculate a hash of the contents, and group the
files by those hashes.  We only need to compare files to others which
hashed to the same value.

Then, compare files within groups, avoiding unnecessary comparisons.

Also, since $a will be compared to a bunch of other files, there's no
need to have compare() open it each -- just open it once, outside the
loop, and seek to the beginning before doing each comparison.

Once a file has been found to be equal to some other file, then we're
not going to compare it to any other files, so splice() it out of the
group.

Having found a group of files which are all equal ($a, @unlink), remove
all in the group except $a (unless one of the others fails to be
removed, in which case $a *should* get removed if possible, since after
all, there's another file which we'll be keeping).

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Thu, 27 Mar 2003 01:39:48 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Faster file comparison?
Message-Id: <3E829CB4.4293C5CB@earthlink.net>

"Jürgen Exner" wrote:
> 
> Michael Perry wrote:
> > Anyone know how this might be made faster? I'm trying to remove
> > identical binary files with different names. This works, but is
> > impractically slow:
> >
> > #!/usr/bin/perl -w
> >
> > use strict;
> >
> > my @contents = glob("*");
> > my $i;
> > my $j;
> >
> > for ($i = 0; $i < @contents; $i++) {
> >         for ($j = ($i+1); $j < @contents; $j++) {
> >                 if (system("cmp $contents[$i] $contents[$j]")=='')
> >                         {unlink($contents[$j])}
> 
> Here you will get into trouble. Because you are unlinking $content[$j]
> effectively you are deleting a file which in a future incarnation of
> the outer loop will be accessed as $content[$i] again but doesn't exit
> any more. You need to remove that entry from the array @content, too.

He *should*, but doesn't have to -- if a file doesn't exist, then the
cmp program will exit with a nonzero value, and system will return a
positive value, and when he does a numeric comparison between system()'s
return value and '', it will be false.


> > --I suspect it's because I'm using the external "cmp" there, but I
> > don't know of a native perl substitute. (And yes, I tried writing
> > this w/o the C-style "for" loop, but it didn't seem to work at all
> > then.)
> 
> I would rather think that the nested loop is killing your performance,
> at least when looking at many files. You got an O(n^2) algorithm here.

There's also the fact that he's using an external program, "cmp",
instead of using File::Compare.

True, "cmp" is likely written in C, whereas File::Compare::compare() is
written in perl, but even so, the time it takes to *start* an external
program (even if it's a fast program) makes a pure-perl solution faster.

> It might be faster if you compute a checksum for each file. This can
> be done in O(n).
>
> And then just compare those files, which have identical checksums.
> This will reduce your n dramatically.
> 
> Or just use the file size as the checksum. It is easy and very fast to
> compute.

Or, two passes -- first put the files into groups with identical sizes,
which should eliminate all files for which there's only one of that
size, (and allow you to avoid checksumming if there're exactly 2 of that
size), then for groups of 3 or more of the same size, perform checksums
to try and divide into smaller groups (and eliminate those files for
which there's only one file with that checksum).

If your checksum is *supremely* trustworthy, such as SHA1, you might
choose to not do another pass, and assume that if they have the same
checksum, they are identical.

Otherwise, you take your now small groups, and perform those O(N^2)
comparisons between all of them.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Thu, 27 Mar 2003 07:09:51 GMT
From: Michael Perry <amperry@provide.net>
Subject: Re: Faster file comparison?
Message-Id: <3txga.21592$pK4.1915555@newsread1.prod.itd.earthlink.net>

Benjamin Goldberg wrote:

> Michael Perry wrote:

<snip>

> 
> use strict;
> use Digest::MD5;
> use File::Compare;
> 
> my @sizegroups = do {
>    my %x;
>    -r && -f _ && push @{ $x{-s _} }, $_ for glob("*");
>    grep @$_ > 1, values %x;
> };
> my ($md, @nextpass);
> foreach my $names (@sizegroups) {
>    if( @$names == 2 ) {
>       push @nexpass, $names;
>       next;
>    }
>    $md ||= Digest::MD5->new;
>    my %bymd;
>    for my $name (@$names) {
>       open( my ($fh), "<", $name )
>          or warn("Couldn't open $name: $!"), next;
>       binmode $fh;
>       push @{ $bymd{$md->addfile($fh)->digest} }, $name;
>    }
>    push @nextpass, grep @$_ > 1, values %bymd;
> }
> my $names = shift @nextpass;
> while( @$names > 2 or $names = shift @nextpass ) {
>    my $a = shift @$names;
>    open( my ($afh), "<", $a )
>       or warn("Couldn't open $a for reading: $!"), next;
>    binmode($afh);
>    my @unlink;
>    for my $j ( reverse 0 .. $#$names ) {
>       my $b = $names->[$j];
>       seek( $afh, 0, 0 );
>       if( open( my ($bfh), "<", $b ) ) {
>          if( compare($afh, $bfh) == 0 ) {
>             print "WOW!\n";
>             print "Two files ($a, $b) with the same MD5 digest,\n";
>             print "but which are unequal!\n";
>             print "Isn't there a prize for this?\n";
>             next;
>          }
>          push @unlink, $b;
>       } else {
>          warn "Error opening $b: $!";
>       }
>       splice @$names, $j, 1;
>    }
>    next unless @unlink;
>    close($afh);
>    my %fail;
>    unlink $_ or push @{$fail{$!}}, $_ for @unlink;
>    unlink $a or push @{$fail{$!}}, $a if %fail;
>    while( my ($err, $files) = each %fail ) {
>       warn "Couldn't unlink [@$files]: $err\n";
>    }
> }
> __END__
> [untested]
> 
> First, group files by size.  We only need to compare files to others
> with the same size.
> 
> Then, for each group, calculate a hash of the contents, and group the
> files by those hashes.  We only need to compare files to others which
> hashed to the same value.
> 
> Then, compare files within groups, avoiding unnecessary comparisons.
> 
> Also, since $a will be compared to a bunch of other files, there's no
> need to have compare() open it each -- just open it once, outside the
> loop, and seek to the beginning before doing each comparison.
> 
> Once a file has been found to be equal to some other file, then we're
> not going to compare it to any other files, so splice() it out of the
> group.
> 
> Having found a group of files which are all equal ($a, @unlink), remove
> all in the group except $a (unless one of the others fails to be
> removed, in which case $a *should* get removed if possible, since after
> all, there's another file which we'll be keeping).
> 
Well, I must say that solution seems faster. I'm using it right now on some 
ttest data (small "hello-world"-ey things copied and renamed in a single 
directory), and it seems to identify some of them, but not others. Still, 
pointing out the File::Compare and MD5 modules will help me figure the rest 
of it out. Thanks!
-- 
Brain for sale. Hardly used.


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

Date: Wed, 26 Mar 2003 11:59:48 -0800
From: mfield <mfield@ernie.botany.ubc.ca>
Subject: global variables with CGI
Message-Id: <3E8206B4.C2108EF9@ernie.botany.ubc.ca>

Sorry if this is the wrong place to post but I couldn't find a CGI
newsgroup (please let me know if there is).
My question is this:
I have a CGI script that runs over and over until a stop button is
pushed. I need a global hash variable that cumulatively adds new keys
and values everytime the same script is run. Is there a way to have this
kind of global hash that is accessible each time the same CGI script is
run? All I can think of is to create a file that stores the hash values
and reloads them everytime but I am hoping there is an easier way.
Thanks in advance, Matt



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

Date: Wed, 26 Mar 2003 23:01:33 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: global variables with CGI
Message-Id: <pan.2003.03.26.21.50.08.505949@aursand.no>

On Wed, 26 Mar 2003 11:59:48 -0800, mfield wrote:
> Sorry if this is the wrong place to post but I couldn't find a CGI
> newsgroup (please let me know if there is).

comp.infosystems.www.authoring.cgi.  As long as your question doesn't have
anything with the Perl programming language, you should post your messages
there.

> I have a CGI script that runs over and over until a stop button is
> pushed. I need a global hash variable that cumulatively adds new keys
> and values everytime the same script is run.

Why?  What does your program do?  Do you need a daemon of some kind
running in the program from which the CGI script can fetch information
from?

More information about your actual problem and situtation is required.
Maybe there are other (and better) ways to solve your problem?

FUT: comp.infosystems.www.authoring.cgi


-- 
Tore Aursand


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

Date: Thu, 27 Mar 2003 00:19:39 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: global variables with CGI
Message-Id: <3E8242E8.4010406@rochester.rr.com>

mfield wrote:

 ...
> I have a CGI script that runs over and over until a stop button is
> pushed. I need a global hash variable that cumulatively adds new keys
> and values everytime the same script is run. Is there a way to have this
> kind of global hash that is accessible each time the same CGI script is
> run? All I can think of is to create a file that stores the hash values
> and reloads them everytime but I am hoping there is an easier way.
> Thanks in advance, Matt
> 
> 

A hash tied to a DBM-type file would meet your needs with minimal 
overhead.  See:

    perldoc -f tie

and docs for DB_File or NDBM_File or SDBM_File etc, whichever is 
implemented on your platform.

-- 
Bob Walton



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

Date: 27 Mar 2003 04:58:36 -0800
From: rpalla@kentlaw.edu (ramesh)
Subject: how to call one program through another program and capture the out put of another program
Message-Id: <2b0865a8.0303270458.2371e3f2@posting.google.com>

hi

How to capture output of perl program into a string?.  for example
 ...one of my program is

program name is subprog1.

sub addition{

$first = 10;
$second = 20;
$third = $first + $second;
return $third;
}
$string2 = addition();
print " the value of third is $string2\n";

return $string2;

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

my next program is to store output of program1 in one string and
printit out.

print "-------------start of program -----------\n\n";
$string1 = system("perl subprog1");

print $string1;

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

but when i execute above program i am getting output as 0 instead of
30.

please help.

Thanks

~


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

Date: Thu, 27 Mar 2003 13:01:41 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: how to call one program through another program and capture the out put of another program
Message-Id: <Xns934B8DD987D9Aelhber1lidotechnet@62.89.127.66>

ramesh wrote:

> hi
> 
> How to capture output of perl program into a string?


If you'd bothered to read the documentation on system() you'd get the 
answer there.


  perldoc -f system


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Thu, 27 Mar 2003 14:27:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: how to call one program through another program and capture the out put of another program
Message-Id: <hTDga.110891$iq1.79488@nwrddc02.gnilink.net>

ramesh wrote:
> How to capture output of perl program into a string?.  for example
> ...one of my program is
[...]
> $string1 = system("perl subprog1");
> print $string1;
>
> but when i execute above program i am getting output as 0 instead of
> 30.

Where did you get the idea that system() would return the output of the
external program?
Did you even bother to read the documentation of the functions you are
using? Apparently not.
Please reread the third paragraph of the system() man page.

jue




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

Date: Thu, 27 Mar 2003 08:27:37 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: how to call one program through another program and capture the out put of another program
Message-Id: <MPG.18ecc657b93ec3ee98976e@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <2b0865a8.0303270458.2371e3f2@posting.google.com>, ramesh 
(rpalla@kentlaw.edu) says...
> hi
> 
> How to capture output of perl program into a string?.  for example
> ...one of my program is
> 
> program name is subprog1.
> 
> sub addition{
> 
> $first = 10;
> $second = 20;
> $third = $first + $second;
> return $third;
> }
> $string2 = addition();
> print " the value of third is $string2\n";
> 
> return $string2;
> 
> --------------------------------
> 
> my next program is to store output of program1 in one string and
> printit out.
> 
> print "-------------start of program -----------\n\n";
> $string1 = system("perl subprog1");
> 
> print $string1;
> 
> ----------------------------------
> 
> but when i execute above program i am getting output as 0 instead of
> 30.
> 

You should check your perl documentation on the use of the backtic 
operator.

$output = `name_of_command arg1 arg2 ...argn`;

-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com


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

Date: 27 Mar 2003 07:58:20 -0800
From: sjk969@hotmail.com (Steve)
Subject: How to determine file creation time
Message-Id: <4123eb1f.0303270758.185b4e5f@posting.google.com>

Greetings from a Perl newbie!

Platform: ActivePerl for Win32, Apache v2.  

I have a script that downloads a file and then displays the file to
the user.  for example:

#!c:\perl\bin\perl.exe 
use strict;
use warnings;
use LWP::Simple;
use CGI;
getstore('http://otherwebsite.com/file.gif','c:\localpath\file.gif');
print "Content-Type: text/html\n\n";
print<<END_OF_TEXT;
<HTML>
<HEAD>
<TITLE>Le Title</TITLE>
</HEAD>
<BODY>
<img src=\"/imagefile.gif\">
</BODY>
</HTML>
END_OF_TEXT

What I would like to do is only do the getstore() function if the file
located at c:\localpath\file.gif was created or modified more than 15
minutes ago, for example.

I've searched around with Google.  I get the impression that it is
possible.  I've tried some snippets of sample code I could find but
can't find code that works for me.

Thank you for your help.


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

Date: Thu, 27 Mar 2003 16:39:01 +0000
From: Andrew McGregor <Andrew.McGregor@amtrak.co.uk>
Subject: Re: How to determine file creation time
Message-Id: <3E832925.5080403@amtrak.co.uk>

Steve wrote:
> 
> What I would like to do is only do the getstore() function if the file
> located at c:\localpath\file.gif was created or modified more than 15
> minutes ago, for example.
> 

perldoc -f stat



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

Date: Thu, 27 Mar 2003 16:42:38 +0000
From: Andrew McGregor <Andrew.McGregor@amtrak.co.uk>
Subject: Re: How to determine file creation time
Message-Id: <3E8329FE.1020605@amtrak.co.uk>

Andrew McGregor wrote:
> Steve wrote:
> 
>>
>> What I would like to do is only do the getstore() function if the file
>> located at c:\localpath\file.gif was created or modified more than 15
>> minutes ago, for example.
>>
> 
> perldoc -f stat
> 


http://www.perldoc.com/perl5.6.1/pod/func/stat.html



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

Date: Thu, 27 Mar 2003 18:22:35 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: sjk969@hotmail.com (Steve)
Subject: Re: How to determine file creation time
Message-Id: <a6ea67371ebcc5d17df412f8abb482fe@news.teranews.com>

>>>>> "Steve" == Steve  <sjk969@hotmail.com> writes:

Steve> Greetings from a Perl newbie!
Steve> Platform: ActivePerl for Win32, Apache v2.  

Good thing you said that, because Unix doesn't have a "creation time",
so I was about to quote you the standard response there. :)

print "Just another Perl hacker,"

-- 
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: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 4767
***************************************


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