[16987] in Perl-Users-Digest
Perl-Users Digest, Issue: 4399 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 21 18:10:31 2000
Date: Thu, 21 Sep 2000 15:10:16 -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: <969574216-v9-i4399@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 21 Sep 2000 Volume: 9 Number: 4399
Today's topics:
Re: Perl Shell on Windows NT <gellyfish@gellyfish.com>
perl/dbi/mysql problem jnk@kenobiz.com
Re: perl/dbi/mysql problem <jeff@vpservices.com>
Re: Portability of Perl/Tk programs? (Tim Hammerquist)
Re: print, chop, \n grrr... <tim@ipac.caltech.edu>
Re: Pure perl encrypt/decryption? (Logan Shaw)
Re: Pure perl encrypt/decryption? (Logan Shaw)
Re: Pure perl encrypt/decryption? <bart.lateur@skynet.be>
pushing an array of records phylobhetto@my-deja.com
Re: pushing an array of records <awright@jwac.osis.gov>
Re: range operator in scalar context <tim@ipac.caltech.edu>
RecDescent bug? <ocschwar@mit.edu>
Re: regex help needed <tim@ipac.caltech.edu>
Re: RegEx Question <usenet@dstanek.com>
Set Cookie and Redirect at same time ??? <Papyros@hp23c.ipt.dtu.dk>
Re: Shortest code for Fibonacci? <thunderbear@bigfoot.com>
Re: Shortest code for Fibonacci? <quantum_mechanic@my-deja.com>
Re: storing HoH in database <bart.lateur@skynet.be>
Re: storing HoH in database (Logan Shaw)
Re: system("cd /var") command <westxga@my-deja.com>
Re: Time help <gellyfish@gellyfish.com>
Tricky Problem rathmore@tierceron.com
Re: Tricky Problem <chrekh@chello.se>
Re: Unrecognized character \327 <bart.lateur@skynet.be>
Re: use of "1;" <tim@ipac.caltech.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Sep 2000 22:27:38 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl Shell on Windows NT
Message-Id: <8qba4a$kpe$1@orpheus.gellyfish.com>
On Wed, 20 Sep 2000 14:54:16 GMT charlie.bursell@healthcare.com wrote:
> I'm not much on Windows, but have recently been forced into it.
>
> On Windows NT, it seems that perl runs in a sub-shell and not in the
> active shell window. I note that I cannot redirect the standard output
> of my perl scripts via ">" or "|".
>
> For example, I create a one line perl script, myperl.pl, with the line,
> print "Hello World\n".
>
> If at the Windows shell prompt, I enter, myperl, I get Hello World as
> expected. However if I enter, myperl > foo, I get no output from the
> perl script and get a file named foo with nothing in it (0 bytes).
>
> Is there a way to make a perl script in Windows NT run in the current
> shell?
This is all a side effect of the FTYPE and ASSOC thing - it will run
fine if you do 'perl myperl.pl' . You might be better off using pl2bat
or using a shell that emulates the Unix shebang.
/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 20:59:40 GMT
From: jnk@kenobiz.com
Subject: perl/dbi/mysql problem
Message-Id: <39cb7669.67788508@news.acronet.net>
#!/usr/local/bin/perl
use DBI;
$dbh = DBI->connect("DBI:mysql:db_kenobiz_com", 'kenobiz_com', '***');
$dbh->do("CREATE TABLE testing (user VARCHAR(15), pass VARCHAR(10))");
$dbh->do("INSERT INTO testing VALUES ('misener', '78dh9as4')");
$dbh->disconnect;
this code succesfully creates the table 'testing' but, it does not
INSERT any data at all, i cant figure this out at all, thanks for any
help you can offer
------------------------------
Date: Thu, 21 Sep 2000 14:05:44 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: perl/dbi/mysql problem
Message-Id: <39CA7828.ED927164@vpservices.com>
jnk@kenobiz.com wrote:
>
> use DBI;
>
> $dbh = DBI->connect("DBI:mysql:db_kenobiz_com", 'kenobiz_com', '***');
> $dbh->do("CREATE TABLE testing (user VARCHAR(15), pass VARCHAR(10))");
> $dbh->do("INSERT INTO testing VALUES ('misener', '78dh9as4')");
> $dbh->disconnect;
>
> this code succesfully creates the table 'testing' but, it does not
> INSERT any data at all, i cant figure this out at all, thanks for any
> help you can offer
I don't know how picky MySQL is, but an ANSI compliant rdbms would
reject your create statement because "user" is a SQL reserved word and
can't be used as a column name. To test this theory (and on general
principles), put a {RaiseError=>1} in your connect statement. If you
don't let DBI tell you what errors are being produced, debugging will be
nothing but guesswork.
--
Jeff
------------------------------
Date: Thu, 21 Sep 2000 21:38:01 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Portability of Perl/Tk programs?
Message-Id: <slrn8sl0mr.p6.tim@degree.ath.cx>
Clinton A. Pierce <clintp@geeksalad.org> wrote:
>David Steuber <nospam@david-steuber.com> writes:
> > I'm considering using Perl/Tk for an application that will use a GUI
> > [...]
> > I already know that there is no fork in Windows.
>
> Bzzzt. Wrong. Has been since 5.6.
I haven't been keeping up on the progress, and I know ActiveState's perl
5.6 was bug-ridden, notably in its fork() implementation. Most 5.6
success stories involved a custom build without fork(). Have they made
progress in this?
--
-Tim Hammerquist <timmy@cpan.org>
Most people are other people. Their thoughts are someone else's
opinions, their lives a mimicry, their passions a quotation.
-- Oscar Wilde
------------------------------
Date: Thu, 21 Sep 2000 11:19:33 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: print, chop, \n grrr...
Message-Id: <39CA5135.1F0314D8@ipac.caltech.edu>
Lou Moran wrote:
[compressed for readability]
> --The exercise was get a user input for a word/phrase and get a user input
> for a number and then get the word/phrase to print as many times as the
> number. No problem. [...snip...]
> --for our purposes the word is Hello, the number is 3, $ is the prompt
>
> print $phrase x $number;
>
> produces:
> HelloHelloHello$
>
> for prettiness I tried
>
> print "$phrase " x $number "\n";
> chop $phrase;
(What's the chop for? What good do you think it's doing *after* the print?)
That shouldn't even have compiled. You need an operator between the $number and
"\n" tokens. You also need Try
print "$phrase " x $number . "\n";
... which works because precedence is working for you. This, to me, makes things
clearer:
print +("$phrase " x $number) . "\n";
(Quiz: Why is that '+' sign there?)
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: 21 Sep 2000 15:16:08 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <8qdqa8$g2t$1@provolone.cs.utexas.edu>
In article <epjjsssqj3hsb4fen895aivqjafpq5kmn8@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>If you don't have telnet access to your site, you can forget about
>installing modules that need compilation. Same thing if your ISP doesn't
>provide access to a C compiler.
If you have CGI access, don't you almost by definition have shell
access? I mean, you can always write a CGI that fork()s itself,
daemonizes its child, happily returns an HTML page in the parent, and
then has the daemonized child essentially emulate telnet and/or a shell
as necessary.
Or, simpler, make a Perl CGI shell. Just have a text blank called
"command", in which you type commands, and then have Perl run whatever
"command" is as a shell command and return the prettified HTML results.
That is, you can do all this as long as your ISP doesn't build a
customized version of Perl that doesn't have system(), fork(), exec(),
connect(), accept(), syscall(), etc.
- Logan
------------------------------
Date: 21 Sep 2000 15:33:22 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <8qdrai$ga0$1@provolone.cs.utexas.edu>
In article <8qdqa8$g2t$1@provolone.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>If you have CGI access, don't you almost by definition have shell
>access? I mean, you can always write a CGI that fork()s itself,
>daemonizes its child, happily returns an HTML page in the parent, and
>then has the daemonized child essentially emulate telnet and/or a shell
>as necessary.
Oops. I typed "telnet" but I meant "telnetd".
- Logan
------------------------------
Date: Thu, 21 Sep 2000 21:41:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <ivvkssclm3c2ti2ufg3n080n3cshgifjhu@4ax.com>
Logan Shaw wrote:
>If you have CGI access, don't you almost by definition have shell
>access? I mean, you can always write a CGI that fork()s itself,
>daemonizes its child, happily returns an HTML page in the parent, and
>then has the daemonized child essentially emulate telnet and/or a shell
>as necessary.
It still runs as "nobody", so there's a limit to what you can do.
I don't think FTP even supports setting the SUID bit; and even then,
some OSes are configured by default to ignore the SUID bit on scripts.
The next choice is to use a cgi-wrap program, but: you need to compile
it on your server. Full circle.
--
Bart.
------------------------------
Date: Thu, 21 Sep 2000 18:41:27 GMT
From: phylobhetto@my-deja.com
Subject: pushing an array of records
Message-Id: <8qdkoh$ds8$1@nnrp1.deja.com>
I'm trying to create an array of records. I get
the contents of a directory and store them in an
array. From there, I split each array element
into the different elements of my record. Now I
need to insert that entire record into a separate
array... that's where the trouble is. My code is
similar to this:
#read in data
@list = `/bin/ls -1`;
#insert data into records
foreach $line (@list) {
($var1,$var2,$var3) = split (/_/,$line);
$rec = {};
$rec -> {TEMP1} = $var1;
$rec -> {TEMP2} = $var2;
$rec -> {TEMP3} = $var3;
push @arrayOfRecords, $rec;
}
I don't know the purpose of the "$rec = {}" but
when it's there, and I print the array, I get the
first item in the @list array. When it's not
there and I print, I get the last item in the
@list array. Either way, I don't get any of the
data in the middle!!!
HELP PLEASE!!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 21 Sep 2000 19:02:38 GMT
From: PhyloBhetto <awright@jwac.osis.gov>
Subject: Re: pushing an array of records
Message-Id: <8qdlvv$fcd$1@nnrp1.deja.com>
Hey folks, I figured it out... it wasn't the code below at all, my
print routine was missing a $ in front of a variable. I hate when that
happens!! :^)
In article <8qdkoh$ds8$1@nnrp1.deja.com>,
phylobhetto@my-deja.com wrote:
> I'm trying to create an array of records. I get
> the contents of a directory and store them in an
> array. From there, I split each array element
> into the different elements of my record. Now I
> need to insert that entire record into a separate
> array... that's where the trouble is. My code is
> similar to this:
>
> #read in data
> @list = `/bin/ls -1`;
>
> #insert data into records
> foreach $line (@list) {
> ($var1,$var2,$var3) = split (/_/,$line);
> $rec = {};
> $rec -> {TEMP1} = $var1;
> $rec -> {TEMP2} = $var2;
> $rec -> {TEMP3} = $var3;
> push @arrayOfRecords, $rec;
> }
>
> I don't know the purpose of the "$rec = {}" but
> when it's there, and I print the array, I get the
> first item in the @list array. When it's not
> there and I print, I get the last item in the
> @list array. Either way, I don't get any of the
> data in the middle!!!
>
> HELP PLEASE!!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 21 Sep 2000 12:21:59 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: range operator in scalar context
Message-Id: <39CA5FD7.D5230878@ipac.caltech.edu>
Wyatt R Johnson wrote:
>
> OK, I find the perlop page to be most unhelpful in explaining
> what the range operator does in scalar context. To quote a bit of it..
> [...snipped...]
> As a scalar operator:
>
> if (101 .. 200) { print; } # print 2nd hundred lines
>
> The way I understand the passage is that in that example, Perl will
> test the value of 101 first. Seeing that it is true, it will continue
> to print $_ each time the if statement is called until the time after
> the right operand tests true. Since 200 is always true, I see this
> code fragment as printing $_ exactly once.
>
> Obviously I am missing something, but I am failing to see what. Could
> someone shed some light on this?
You're missing this statement from perlop:
"If either
operand of scalar ".." is a constant expression, that
operand is implicitly compared to the $. variable, the
current line number."
If any of the Perl greater powers are reading, I have a related question:
By coincidence, I was just considering code similar to this:
# -w and strict on
print if /ad/..."af" for ("aa".."az");
This prints:
adaeafagahaiajakalamanaoapaqarasatauavawaxayaz
The docs do not explicitly cover what happens if one of the expressions is not
either a match op nor a numeric. As I read them one could believe either
a) the string "af" should be coerced into a numeric to compare it to $., which
will never be true, or
b) the string is evaluated as a boolean true and only the "adae" should be
printed, or
c) the string "af" is somehow interpreted as an RE (as for split) and will thus
print "adaeaf".
Given what's printed, it looks like it's a). But why no warning for attempting
to coerce a non-numeric string into a numeric?
As for the OP, did I miss some text somewhere?
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Thu, 21 Sep 2000 15:13:02 -0400
From: Omri Schwarz <ocschwar@mit.edu>
Subject: RecDescent bug?
Message-Id: <39CA5DBE.68A3DA95@mit.edu>
Hi, all. I have a rule that goes like this:
primary_expression :
identifier
{
$return = $item{identifier};
print STDERR 'x';
}
|
'the'
( /\\d+/
'-layered'
{ $return = $item[1]; }
)(?)
'parenthetical' 'expression'
{
my $addon;
my $level = join('',@{$item[-3]});
$level --;
$addon = ' the parenthetical expression ' x $level;
$text = $addon . $text;
print STDERR "start paren\n";
}
expression
( 'now'
| '(' 'now' 'drop' /\\d+/ 'layers' 'of' 'context' ')'
{
my $level = $item[4] ;
$level --;
my $addon2 = ' now ';
$addon2 x= $level;
$text = $addon2 . $text;
$return = $level;
}
)
{
$return = "($item{expression})";
print STDERR "paren $return\n";
}
And yet when I turn on RD_TRACE,
I get this:
Parse::RecDescent: Treating "primary_expression :" as a rule
declaration
Parse::RecDescent: Treating "identifier" as a subrule match
Parse::RecDescent: Treating "{ $return = $item{identifier}; print
STDERR
'x'; }" as an action
Parse::RecDescent: Treating "|" as a new production
Parse::RecDescent: Treating "the" as a literal terminal
Parse::RecDescent: Treating "( /\d+/ '-layered' { $return =
$item[1]; } )"
as an implicit subrule
Parse::RecDescent: Treating
"_alternation_1_of_production_2_of_rule_primary_express
ion :" as a rule declaration
Parse::RecDescent: Treating "/\d+/" as a /../ pattern terminal
Parse::RecDescent: Treating "-layered" as a literal terminal
Parse::RecDescent: Treating "{ $return = $item[1]; }" as an action
Parse::RecDescent: Treating
"_alternation_1_of_production_2_of_rule_primary_express
ion(?)" as an zero-or-one subrule match
Parse::RecDescent: Treating "parenthetical" as a literal terminal
Parse::RecDescent: Treating "expression" as a literal terminal
Parse::RecDescent: Treating "{ my $addon; my $level =
join('',@{$item[-
3]}); $level --; $addon = ' the parenthetical
expression ' x $level; $text = $addon . $text;
print
STDERR "start paren\n"; }" as an action
Parse::RecDescent: Treating "expression" as a subrule match
Warning: Undefined (sub)rule "ordinal" used in a
production.
And parsing ends.
The grammar begins with:
my $Grammar = q[
...
Could anyone guess why this breaks?
------------------------------
Date: Thu, 21 Sep 2000 11:51:01 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: regex help needed
Message-Id: <39CA5895.AF6BAF4E@ipac.caltech.edu>
Phil R Lawrence wrote:
>
> I want a list of all the methods I've used in a directory full of files.
> First, I grep'd all the lines out of some files that have '$r->'.
> This results in a file full of lines like this:
> AIAthletes.pm:$r->add_custom_sql_clause('c_ints',
> 'saturn.sorints', @c_ints);
> AIAthletes.pm:my $sth_offers_sd = $r->prepare(
>
> What regex can i use to throw out everything except:
> $r->method_name(@parms) ?
>
> I tried:
> #!/usr/local/bin/perl -w
> while (<>) {
> print "$_\n"; #before
> s/[^(\$r\->\w+)]//g;
Better read perlre. That certainly doesn't do remotely what you appear to think
it does. Perhaps you were going for something more like
while (<>) {
print "$1\n" while /(\$r->\w+)/g;
}
... which *may* work, if your code is simple and consistent enough. By and large
you'll have to face this fact: Perl is hard to parse.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Thu, 21 Sep 2000 14:39:40 -0400
From: "David Stanek" <usenet@dstanek.com>
Subject: Re: RegEx Question
Message-Id: <8qdkem$t3n$1@news.chatlink.com>
Great thanks, it works perfectly.
David Stanek
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:m82kssc3rumbimou4q02k65ap6ar5j0c4v@4ax.com...
> David Stanek wrote:
>
> >Is there any way to do something like [^(</blockquote>)] so I can say get
> >any character until it gets to </blockquote>?
>
> The usual answer is to match using a nongreedy subpattern:
>
> m~(.*?)(?=\z|</blockquote>)~s and print $1;
>
> which will match everything up to the first "</blockquote>", or the end
> of the string. But here is an alternative:
>
> m~(([^<]+|<(?!/blockquote>))*)~s and print $1;
>
> Here, the subpattern will match a repetition of any character but "<",
> or a "<" provided it is not followed by "/lockquote>".
>
> --
> Bart.
------------------------------
Date: Thu, 21 Sep 2000 23:23:29 +0100
From: "Papyros Brandmand" <Papyros@hp23c.ipt.dtu.dk>
Subject: Set Cookie and Redirect at same time ???
Message-Id: <8qdufj$1l3$1@news.inet.tele.dk>
Can someone help here...
i'am trying på make some CGI (Not that good to perl)...
I need to set a cookie and Redirect to another site at the same time...
Put i can only do one of the thing... only one of them will work ???
Please help me....
Papyros
------------------------------
Date: Thu, 21 Sep 2000 20:08:49 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39CA4EB1.7E29611D@bigfoot.com>
Jim Cook wrote:
> I cite as evidence to my claim that using exponentiation is O(1) for the
> limited set of real numbers available on the Intel FPU the following
> program and results. Perhaps I put too much faith in "use benchmark".
Exponentiation is most likely implemented as exp( log( base) * power).
These three operations most likely run almost liniarly regardless of the
size of the numbers.
--
Thorbjørn Ravn Andersen "...plus...Tubular Bells!"
http://bigfoot.com/~thunderbear
------------------------------
Date: Thu, 21 Sep 2000 20:56:25 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <8qdsla$o48$1@nnrp1.deja.com>
In article <39c1c5ee.5f9e$1f8@news.op.net>,
mjd@plover.com (Mark-Jason Dominus) wrote:
> There may be a faster O(log n) algorithm that is based more directly
> on the identity
>
> F(2n) = F(n)(F(n+1) + F(n-1))
>
> but it's past 2:30 AM here and I can't remember it offhand.
I just thought you folks would be interested in trying some of the
other Fib identities as well, such as:
F(n*n) = F(n-1)*F(n*(n-1)) + F(n)*F(n*(n+1))
F(2n) = F(n+1)^2 - F(n-1)^2 (note subtraction)
F(2n+1) = F(n+1)^2 + F(n)^2
F(3n) = F(n+1)^3 + F(n)^3 + F(n-1)^3
F(m+n) = F(n-1)*F(m) + F(n)*F(m+1)
(found or derived from
http://mathworld.wolfram.com/FibonacciNumber.html)
There are some more formulae and links at
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibFormulae.html.
Perhaps a program could partition "n" appropriately for the best
performance. Hrmmmm....sounds like a good diversion for me.
QM
--
Quantum Mechanics: The dreams stuff is made of.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 21 Sep 2000 18:45:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: storing HoH in database
Message-Id: <5nlkss49th5nfcl2j1jo9c0jpep9e4lb41@4ax.com>
Rich More wrote:
>> How would you store hashes of hashes in a database, in particular on
>>MS SQL server?
>
>Try: Data::Dumper or FreezeThaw to stringify the hash.
<smack forehead> Of course! All I remembered was that databases can't
store lists of lists.
OTOH, the problem with this approach is that you can't readily access
the data in the database without assistence from Perl.
--
Bart.
------------------------------
Date: 21 Sep 2000 15:25:39 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: storing HoH in database
Message-Id: <8qdqs3$g5u$1@provolone.cs.utexas.edu>
In article <5nlkss49th5nfcl2j1jo9c0jpep9e4lb41@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Rich More wrote:
>>> How would you store hashes of hashes in a database
>>Try: Data::Dumper or FreezeThaw to stringify the hash.
>OTOH, the problem with this approach is that you can't readily access
>the data in the database without assistence from Perl.
On the other other hand, it's not that terribly hard to build something
that can stringify *only* hashes of hashes and which has the additional
properties that the stringification algorithm isn't opaque and doesn't
require a Perl interpreter to implement.
Scalar values can be stringified with something like this:
$scalar =~ s/(^[A-Za-z0-9_])/"{".ord($1)."}"/eg;
And a hash can be stringified by doing something like this:
$string = join (",", map ( ( "$_"=>$hash{$_} ), keys %hash ));
provided, of course, that all its keys and values have been
pre-stringified (even if they are references to hashes!). If you
don't care to make the key-value nature apparent in your representation,
just do this instead:
$string = join (":", %hash);
Decoding them is easy enough. If you want to get really fancy, include
characters in the stringification that indicate types so that you can
conditionally restore and have more complex data structures. Or, don't
bother if you only want hashes of hashes.
Note: the code above is from memory from a few months ago. I'm not
sure if it's actually what I used when I did exactly this, but I
think it's the general idea.
Of course, this is not terribly clean, but it will work and it has in
favor of it that it's feasible (if not fun or nice) to access the data
from other languages.
Hope that helps.
- Logan
------------------------------
Date: Thu, 21 Sep 2000 18:03:12 GMT
From: Glenn West <westxga@my-deja.com>
Subject: Re: system("cd /var") command
Message-Id: <8qdigh$ats$1@nnrp1.deja.com>
In article <8qdg4q$7tm$1@nnrp1.deja.com>,
aravindh@technologist.com wrote:
> Hi,
>
> I want to execute the unix command - cd /var/ within perl. I know I
> should be doing system("cd /var/") or system("cd \/var\/") command.
but
> don't seem to work. how can i do this?
>
The key word here is that it doesn't SEEM to work. It probably did
work. The problem is that the system call resulted in a subshell being
launched. The cd command executed in the subshell. Then the subshell
exited. So your program's environment never changed. As another
poster indicated, you want the perl function chdir.
HTH
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 20 Sep 2000 22:23:37 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Time help
Message-Id: <8qb9sp$kp3$1@orpheus.gellyfish.com>
On 20 Sep 2000 18:40:26 GMT John J. Trammell wrote:
> On Wed, 20 Sep 2000 10:40:06 -0500, Tom Briles <sariq@texas.net> wrote:
>>"John J. Trammell" wrote:
>>>
>>> On Wed, 20 Sep 2000 14:54:30 +0100, Rui Miguel Venancio
>>> <rui.miguel@srd.alcatel.pt> wrote:
>>>
>>> >I have one variable with the system date (eg. 20000919 - YYYYMMDD),
>>> >And I have another variable with a date in the future
>>> >(eg: 20001005 - YYYYMMDD).
>>> >
>>> >I want to see a message if the second date have less than 4 weeks of
>>> >the first date !!!!
>>>
>>> You're looking for the Date::Calc module and its Delta_Days function.
>>
>>That's overkill. The formatted dates shown are very easily parsed for
>>input into the timelocal() function.
>>
>
> I've put it to the test; here's the output of my Benchmark:
>
> [ ~/test/time-001 ] ./foo.pl
> Benchmark: timing 10000 iterations of date-calc, time-local...
> date-calc: 2 wallclock secs ( 1.61 usr + 0.00 sys = 1.61 CPU)
> @ 6211.18/s (n=10000)
> time-local: 12 wallclock secs (11.76 usr + 0.00 sys = 11.76 CPU)
> @ 850.34/s (n=10000)
> [ ~/test/time-001 ]
>
> This is for routines that do identical parsing of strings, then either
> - call Date::Calc::Delta_Days
> - use Time::Local to calculate Epoch seconds, take the
> difference, and divide by 24*3600
> then use the result in a comparison against 28 days.
>
> Anyone able to confirm or deny this? Looks like Date::Calc is
> simpler and faster to me.
>
Date::Calc has a C core so it should be faster. I think part of the overkill
thing comes from the fact that Time::Local is in the distribution and
Date::Calc doesnt.
/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:18:22 GMT
From: rathmore@tierceron.com
Subject: Tricky Problem
Message-Id: <8qdmt7$gmu$1@nnrp1.deja.com>
Problem: My Perl program reviews a directory once an hour to see if a
file exists in that directory. If the file exists the program runs, if
not it does nothing. However, if 2 hours go buy without a file being
found in that directory, the program emails me.
How do I accomplish this? I thought I'd create a "No File Found" log
and if that log exists and there is no other file in the directory then
it would email me. (The program would delete any "No File Found" log
before exiting so that there would either be no log, signifying
everything is fine, or 1 log signifying there was a problem last hour.)
Is there a better, cleaner, easier, way to do this?
Thanks!
Rathmore
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 21 Sep 2000 20:28:12 GMT
From: Christer Ekholm <chrekh@chello.se>
Subject: Re: Tricky Problem
Message-Id: <86n1h18pbg.fsf@jane.localdomain>
rathmore@tierceron.com writes:
> Problem: My Perl program reviews a directory once an hour to see if a
> file exists in that directory. If the file exists the program runs, if
> not it does nothing. However, if 2 hours go buy without a file being
> found in that directory, the program emails me.
>
> How do I accomplish this? I thought I'd create a "No File Found" log
> and if that log exists and there is no other file in the directory then
> it would email me. (The program would delete any "No File Found" log
> before exiting so that there would either be no log, signifying
> everything is fine, or 1 log signifying there was a problem last hour.)
>
> Is there a better, cleaner, easier, way to do this?
Perhaps something like this. OBS untested!
my $fail_count = 0;
while (1) {
if ( -f "dir/file" ) {
$fail_count = 0;
#
# code to do real work
#
}else{
$fail_count++;
if ( $fail_count > 1 ) {
#
# code to mail warning
#
}
}
sleep( 60 * 60 );
}
/ Christer
------------------------------
Date: Thu, 21 Sep 2000 18:50:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Unrecognized character \327
Message-Id: <r1mksskpgpil5qsdpuu655mh5qrnt0e7if@4ax.com>
udoline wrote:
>Unrecognized character \327 at test.pe line 2.
On Windows, that's a times sign, which looks like a small "x". Maybe you
should use a plain "x" instead?
--
Bart.
------------------------------
Date: Thu, 21 Sep 2000 11:59:28 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: use of "1;"
Message-Id: <39CA5A90.683B01AC@ipac.caltech.edu>
Beggar wrote:
> what is the use of this line:
>
> 1;
perldoc -f require
Read first, ask later.
"The file must return true as the last statement to indicate
successful execution of any initialization code, so it's customary to
end such a file with C<1;> unless you're sure it'll return true
otherwise. But it's better just to put the C<1;>, in case you add more
statements."
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
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 4399
**************************************