[24940] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7190 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 29 11:06:53 2004

Date: Wed, 29 Sep 2004 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 29 Sep 2004     Volume: 10 Number: 7190

Today's topics:
        #define-like feature in Perl (Yash)
    Re: #define-like feature in Perl <1usa@llenroc.ude.invalid>
    Re: #define-like feature in Perl <ron.parker@povray.org>
    Re: #define-like feature in Perl <no@email.com>
        ANNOUNCE: WWW::Webrobot 0.50 <webrobot@abas.de>
    Re: CGI.pm sticky hidden fields: why? <bernie@fantasyfarm.com>
        counting number of occurrences of every possible substr <_>
    Re: counting number of occurrences of every possible su <tadmc@augustmail.com>
    Re: counting number of occurrences of every possible su <mritty@gmail.com>
    Re: help with eval <tadmc@augustmail.com>
    Re: HTTP::Cookies cookie_jar %rest hash <thepoet_nospam@arcor.de>
        match a long string in Regex.. <end@dream.life>
    Re: match a long string in Regex.. <mritty@gmail.com>
    Re: Optionally changing file perms? (Anno Siegel)
    Re: use require and loading modules <noreply@gunnar.cc>
    Re: use require and loading modules <shawn.corey@sympatico.ca>
    Re: What is this error? <bik.mido@tiscalinet.it>
        Write filename w/ scalar and bareword (mt35)
    Re: Write filename w/ scalar and bareword <1usa@llenroc.ude.invalid>
    Re: Write filename w/ scalar and bareword <tore@aursand.no>
    Re: Write filename w/ scalar and bareword <tadmc@augustmail.com>
    Re: Write filename w/ scalar and bareword <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 29 Sep 2004 05:55:50 -0700
From: yashgt@yahoo.com (Yash)
Subject: #define-like feature in Perl
Message-Id: <5a373b1d.0409290455.23f5bbee@posting.google.com>

Hi,

In a perl 5.8 program, We have to use a long list of variables in a
certain order in a number of places. It is something like:
my ($var1, $field2, $a3, $b4, .....) ;
	.
	.
	.
foreach $x ($var1, $field2, $a3, $b4, .....) {
	$x = -1 ;
}
	.	
	.
	.
print join(",",($var1, $field2, $a3, $b4, .....)) ;


Instead of having to repeat the names of the fields and their order,
in all places of use, we would like to have something like
#define FIELD_LIST $var1, $field2, $a3, $b4, .....

and user FIELD_LIST in all places.
This is important for us as the fields and their order may change as
the program evolves.
Can somebody suggest a better alternative?

Thanks


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

Date: 29 Sep 2004 13:07:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: #define-like feature in Perl
Message-Id: <Xns95735CC3C606Aasu1cornelledu@132.236.56.8>

yashgt@yahoo.com (Yash) wrote in 
news:5a373b1d.0409290455.23f5bbee@posting.google.com:

> In a perl 5.8 program, We have to use a long list of variables in a
> certain order in a number of places. It is something like:
> my ($var1, $field2, $a3, $b4, .....) ;
>      .
>      .
>      .
> foreach $x ($var1, $field2, $a3, $b4, .....) {
>      $x = -1 ;
> }
>      .     
>      .
>      .
> print join(",",($var1, $field2, $a3, $b4, .....)) ;
> 
> Instead of having to repeat the names of the fields and their order,
> in all places of use, we would like to have something like
> #define FIELD_LIST $var1, $field2, $a3, $b4, .....
> 
> and user FIELD_LIST in all places.
> This is important for us as the fields and their order may change as
> the program evolves.
> Can somebody suggest a better alternative?

Consider the following alternative to the example you gave above:

#! perl

use strict;
use warnings;

my %hash = (var1 => 1, field2 => 2, a3 => 3, b4 => 4);

$_ = -1 for (values %hash);
print join ',', values %hash;

__END__

Sinan


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

Date: Wed, 29 Sep 2004 09:32:01 -0500
From: Ron Parker <ron.parker@povray.org>
Subject: Re: #define-like feature in Perl
Message-Id: <slrncllhr1.fdv.ron.parker@mail.parkrrrr.com>

On 29 Sep 2004 13:07:09 GMT, A. Sinan Unur wrote:
> print join ',', values %hash;

$ perldoc -f values
=item values HASH

Returns a list consisting of all the values of the named hash.  (In a
scalar context, returns the number of values.)  The values are
returned in an apparently random order.
----

You don't think that "random order" thing might be a problem?

-- 
#local R=<7084844682857967,0787982,826975826580>;#macro L(P)concat(#while(P)chr(
mod(P,100)),#local P=P/100;#end"")#end background{rgb 1}text{ttf L(R.x)L(R.y)0,0
translate<-.8,0,-1>}text{ttf L(R.x)L(R.z)0,0translate<-1.6,-.75,-1>}sphere{z/9e3
4/26/2001finish{reflection 1}}//ron.parker@povray.org My opinions, nobody else's


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

Date: Wed, 29 Sep 2004 16:00:38 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: #define-like feature in Perl
Message-Id: <2s010sF1fbmopU1@uni-berlin.de>


"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns95735CC3C606Aasu1cornelledu@132.236.56.8...
> yashgt@yahoo.com (Yash) wrote in
> news:5a373b1d.0409290455.23f5bbee@posting.google.com:
>
> > In a perl 5.8 program, We have to use a long list of variables in a
> > certain order in a number of places. It is something like:
> > my ($var1, $field2, $a3, $b4, .....) ;
> >      .
> >      .
> >      .
> > foreach $x ($var1, $field2, $a3, $b4, .....) {
> >      $x = -1 ;
> > }
> >      .
> >      .
> >      .
> > print join(",",($var1, $field2, $a3, $b4, .....)) ;
> >
> > Instead of having to repeat the names of the fields and their order,
> > in all places of use, we would like to have something like
> > #define FIELD_LIST $var1, $field2, $a3, $b4, .....
> >
> > and user FIELD_LIST in all places.
> > This is important for us as the fields and their order may change as
> > the program evolves.
> > Can somebody suggest a better alternative?
>
> Consider the following alternative to the example you gave above:
>
> #! perl
>
> use strict;
> use warnings;
>
> my %hash = (var1 => 1, field2 => 2, a3 => 3, b4 => 4);
>
> $_ = -1 for (values %hash);
> print join ',', values %hash;


But this wouldn't necessarily join them in the correct order.  It wouldn't
matter if they were all of equal value, but I doubt this is what the OP
wanted.

my @array = (1, 2, 3, 4);
print join ',',@array;

-- 
Brian Wakem




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

Date: Wed, 29 Sep 2004 09:46:23 GMT
From: Stefan Trcek <webrobot@abas.de>
Subject: ANNOUNCE: WWW::Webrobot 0.50
Message-Id: <I4su69.LwF@zorch.sf-bay.org>

Webrobot http://search.cpan.org/dist/webrobot/ is a data driven http
client heavily based on LWP.  It can be used

* for automating http requests
* for a kind of web based unit tests
* for stress tests of web servers (limited).

For more information see the README in the distribution
http://search.cpan.org/dist/webrobot/lib/WWW/Webrobot/pod/README.pod
and the support page http://webrobot.abas.de containing screenshots
and tutorials.

Stefan




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

Date: Wed, 29 Sep 2004 10:39:33 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: CGI.pm sticky hidden fields: why?
Message-Id: <8mhll0l2s9klgm8vnhod54d24n2u21obet@library.airnews.net>

ioneabu@yahoo.com (wana) wrote:

} Is there any justification for the 'stickiness' of hidden fields?  A
} web page viewer cannot legitimately enter a value into a hidden field,
} so why would anyone want to hold over a value to the next page?

I think it is a matter of the underlying philosophy of the CGI module: I
get the impression that the intent is to use the form data as a sort-of
'poor man's session' and so as you go out to the user and come back to your
CGI it tries pretty hard to preserve the "state" of things.  That's just
the way CGI works....

} I really got stuck on this one for a while because I was creating a
} session and passing the session id in a hidden field and it was
} getting stuck there and not changing when it was supposed to until I
} added -override=>1.

I've gotten stuck by this, too.  What I do now is a bit of a kludge but
works for the way I think about CGI pgms: I do:
    my $cgi = new CGI;   # Get the actual CGI data
    new CGI ;            # Create an *empty* new CGI for the "outgoing"

I then do all of my "incoming variables" via $cgi, but do the outbound form
via the "default CGI object" and so the workaround completely turns off the
'stickiness'.

  /Bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Thu, 30 Sep 2004 00:09:29 +1000
From: "C3" <_>
Subject: counting number of occurrences of every possible substring in multiple files
Message-Id: <415ac218$0$20582$afc38c87@news.optusnet.com.au>

I am trying to write a program that reads multiple files and prints out the 
number of occurrences of n-length byte sequences across these files. the 
value of n must be specified on the command-line.

Since I'll be dealing with binary files, I want the ASCII codes of the 
characters printed out.

e.g. for n=2 and the following 3 files, contents shown as integers,

f1 = {33, 84, 55}, f2 = {84, 55, 12}, f3 = {33, 84, 55}

I want output like this:
3    84 55
2    33 84

I'll be dealing with files up to about one megabyte in size. Efficiency is 
not critical, and it does not matter, say, if a length-2 sequence is a 
substring of a length-3, or a more frequently occurring sequence. Values of 
n will not go above 10.





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

Date: Wed, 29 Sep 2004 09:48:55 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: counting number of occurrences of every possible substring in multiple files
Message-Id: <slrnclliqn.i79.tadmc@magna.augustmail.com>

C3 <> wrote:
> I am trying to write a program that reads multiple files and prints out the 
> number of occurrences of n-length byte sequences across these files. the 
> value of n must be specified on the command-line.
> 
> Since I'll be dealing with binary files, 


   perldoc -f binmode


> I want the ASCII codes of the 
> characters printed out.


Huh?

If it is a text file, then it contains ASCII codes.

If it is a binary file, then it may contain some other encoding.

Anyway,

   perldoc -f chr
   perldoc -f ord


> e.g. for n=2 and the following 3 files, contents shown as integers,
> 
> f1 = {33, 84, 55}, f2 = {84, 55, 12}, f3 = {33, 84, 55}
> 
> I want output like this:
> 3    84 55
> 2    33 84
> 
> I'll be dealing with files up to about one megabyte in size. Efficiency is 
> not critical, and it does not matter, say, if a length-2 sequence is a 
> substring of a length-3, or a more frequently occurring sequence. Values of 
> n will not go above 10.


Did you mean to ask a question?

What is it that you need help with?

Are you asking for someone to write a program to your specification
for you? It kind of sounds that way...


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


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

Date: Wed, 29 Sep 2004 14:57:31 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: counting number of occurrences of every possible substring in multiple files
Message-Id: <v3A6d.6084$r%4.2009@trndny05>

"C3" <_> wrote in message
news:415ac218$0$20582$afc38c87@news.optusnet.com.au...
> I am trying to write a program that reads multiple files and prints
out the
> number of occurrences of n-length byte sequences across these files.
the
> value of n must be specified on the command-line.
>
> Since I'll be dealing with binary files, I want the ASCII codes of the
> characters printed out.
>
> e.g. for n=2 and the following 3 files, contents shown as integers,
>
> f1 = {33, 84, 55}, f2 = {84, 55, 12}, f3 = {33, 84, 55}
>
> I want output like this:
> 3    84 55
> 2    33 84
>
> I'll be dealing with files up to about one megabyte in size.
Efficiency is
> not critical, and it does not matter, say, if a length-2 sequence is a
> substring of a length-3, or a more frequently occurring sequence.
Values of
> n will not go above 10.

Do you realize that no where in here did you ask a question?  What is it
you need help with?  What part are you stuck on?  What have you tried so
far, and how did your attempt fail to work correctly?

Paul Lalli




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

Date: Wed, 29 Sep 2004 07:57:39 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: help with eval
Message-Id: <slrncllca3.huu.tadmc@magna.augustmail.com>

Alex  Lee <simplitia@gmail.com> wrote:

> I am getting this weird error message 


It is not weird at all, it is a normal syntax error message,
the same as if it was in a conventional program rather than
in an eval EXPR.


> from eval even when @$ is not
                      ^^
                      ^^  huh?
> set.


Did you mean $@ instead?

For me it says:

   syntax error at (eval 1) line 1, near "**1"


> example:
> eval '**1';


The exponentiation operator requires 2 operands, you have given
it only one.


> yeilds erorr outpu:
> Number found where operator expected at (eval 1) line 1, near "**1"
> (Missing operator before 1?)

> Does anyone know how I can silence this error from eval? 


By giving it code that is free of syntax errors.


> I read
> something about patches for certain versions of perl, but do not have
> any details. 


That code will fail to run in all versions of Perl...




"eval EXPR" is dangerous and not for beginners.

What is it that you are actually trying to accomplish?

You can almost certainly get it done without resorting to the evil eval().



Have you seen the Posting Guidelines that are posted here frequently?


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


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

Date: Wed, 29 Sep 2004 14:12:50 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: HTTP::Cookies cookie_jar %rest hash
Message-Id: <415aa6c2$0$8117$9b4e6d93@newsread4.arcor-online.net>

bigDWK wrote:
> From the HTTP::Cookies man page it shows this function
> 
> I believe I have the most current version of HTTP::Cookies (cpan tells
> me I do).
> 
> $cookie_jar->scan( \&callback );
>            The argument is a subroutine that will be invoked for
>            each cookie stored in the $cookie_jar.  The subroutine
>            will be invoked with the following arguments:
> 
>              0  version
>              1  key
>              2  val
>              3  path
>              4  domain
>              5  port
>              6  path_spec
>              7  secure
>              8  expires
>              9  discard
>             10  hash
> 
> I can retrieve all this info, but i'm having problems getting the
> values out of the hash that's returned.  Here's my code

The hash is passed to callback() as a hashref, so what you need
to do to read its value is dereference it like:

my $hashref = pop @_;
for( keys %{$hashref} ) {
	print $_ . " -> " . $hashref->{$_} . $/;
}

Be aware that most cookies provide only the standard set of
attributes that are recongnized by HTTP::Cookies, so $hashref
points to an empty hash. If you want to be sure, use Data::Dumper
to see if %$hashref really is empty.

HTH
-Christian


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

Date: Wed, 29 Sep 2004 20:38:59 +0800
From: Alont <end@dream.life>
Subject: match a long string in Regex..
Message-Id: <415aa574.30926250@130.133.1.4>

original string:(it's one line):
javascript:if(confirm('http://validator.w3.org/  \n\nThis file was not
retrieved by Teleport Pro, because it is addressed on a domain or path
outside the boundaries set for its Starting Address.  \n\nDo you want
to open it from the server?'))window.location='

because 'http://validator.w3.org/' is variable, so I wrote:

javascript:if\(confirm\('(.*|(\\n)*)  \\n\\nThis file was not
retrieved by Teleport Pro, because it is addressed on a domain or path
outside the boundaries set for its Starting Address\.  \\n\\nDo you
want to open it from the server?'))window.location='

I have tried/change again and again,
but it can't match, why?

this is all the code:

sub deleteTrash {
my $original = "javascript:if\(confirm\('(.*|(\\n)*)  \\n\\nThis file
was not retrieved by Teleport Pro, because it is addressed on a domain
or path outside the boundaries set for its Starting Address\.
\\n\\nDo you want to open it from the
server\?'\)\)window\.location='";
my $body = shift;
if($body =~ s/$original//g) 
	{
	return 0;		
	}
else
	{
	return $body;
	}
}

-- 
      Your fault as a Government is My failure as a Citizen.


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

Date: Wed, 29 Sep 2004 13:11:43 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: match a long string in Regex..
Message-Id: <jwy6d.17316$M45.11406@trndny09>

"Alont" <end@dream.life> wrote in message
news:415aa574.30926250@130.133.1.4...
> I have tried/change again and again,
> but it can't match, why?
>
> this is all the code:
>
> sub deleteTrash {
> my $original = "javascript:if\(confirm\('(.*|(\\n)*)  \\n\\nThis file
> was not retrieved by Teleport Pro, because it is addressed on a domain
> or path outside the boundaries set for its Starting Address\.
> \\n\\nDo you want to open it from the
> server\?'\)\)window\.location='";

The four embedded newlines hear actually need to be doubly escaped.
That is, the string should contain: \\\\n\\\\n rather than \\n\\n.  This
is because pattern matching passes through two sets of interpolation.
First for double-quotish interpolation, then for regular expression
interpolation.

Additionally, because you are using double quotes to create $original,
\(  gets treated as an actual parentheses, which is then interpolated by
the RegExp engine to mean "start capture".  I would suggest changing to
single-quotes here:
my $original = q[javascript:if\(confirm\('(.*|\\n*)  \\\\n\\\\nThis file
was not retrieved by Teleport Pro, because it is addressed on a domain
or path outside the boundaries set for its Starting Address\.
\\\\n\\\\nDo you want to open it from the
server\?'\)\)window\.location='];
#all the above on one line

One more thing - I don't think you're doing what you think you're doing
with (.*|\n*).  That will match any sequence of non-newlines, or any
sequence of newlines.  It will not match any sequence of characters
which contains newlines.  For that, stick with .* and add the /s switch
to the pattern match.

Paul Lalli


> my $body = shift;
> if($body =~ s/$original//g)
> {
> return 0;
> }
> else
> {
> return $body;
> }
> }
>
> -- 
>       Your fault as a Government is My failure as a Citizen.




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

Date: 29 Sep 2004 12:04:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Optionally changing file perms?
Message-Id: <cje8cf$nvh$1@mamenchi.zrz.TU-Berlin.DE>

Doug O'Leary  <dkoleary@olearycomputers.com> wrote in comp.lang.perl.misc:
> On 2004-09-23, Greg Bacon <gbacon@hiwaay.net> wrote:
> >
> > I can't reproduce that result:
> >
> >     0660 0760 ./foo
> >     0770 0770 ./bar
> >
> > Hmm.. did you import the S_I* symbols using the Fcntl module?  Is
> > perl treating them as barewords in your program, in other words?
> 
> Well, it's good to know the logic is correct.  I tried doing
> the use Fcntl thing; however, I get a core dump on my HP 11.00 perl
> v5.6.  While browing through documentation, I found 
> use POSIX ":fcntl_h".  My half-formed thought was that the POSIX
> module was Fcntl's successor.  POSIX *seemed* to work - at least it 
> compiled and ran.  Apparently, those constants aren't defined...

They are, but strangely not all of them under the ":fcntl_h" tag.
Some are in ":sys_stat_h".  Request both, or just "use POSIX;"
without qualification to get them all.

Anno


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

Date: Wed, 29 Sep 2004 12:23:39 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: use require and loading modules
Message-Id: <2rvgq1F1far37U1@uni-berlin.de>

buildmorelines wrote:
> is there any way to load modules after the initial compilation, as
> needed/on the fly/dynamically, so I wont be loading code that will
> not get used?

     require MyModule;

does just that, i.e. the module gets loaded only if and when that
statement is executed.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 29 Sep 2004 07:09:34 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: use require and loading modules
Message-Id: <ZIw6d.10849$tT2.996345@news20.bellglobal.com>

Gunnar Hjalmarsson wrote:
> buildmorelines wrote:
> 
>> is there any way to load modules after the initial compilation, as
>> needed/on the fly/dynamically, so I wont be loading code that will
>> not get used?
> 
> 
>     require MyModule;
> 
> does just that, i.e. the module gets loaded only if and when that
> statement is executed.
> 

See perldoc perlmod.

use MyModule;

is equivalent to

BEGIN{ require MyModule; import MyModule; }

and

use MyModule @LIST;

is

BEGIN{ require MyModule; import MyModule @LIST; }

	--- Shawn


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

Date: Wed, 29 Sep 2004 15:25:10 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: What is this error?
Message-Id: <5pdll05r6sfabrlpsaa0kutob0na260cbi@4ax.com>

On 28 Sep 2004 12:19:29 -0700, binnyva@hotmail.com (Binny V A) wrote:

># Get a list of all matching files
>my $list;
>$list = `dir /b *.htm`;
>my @LIST = split(/\s+/, $list);

Whatever you're trying to do, you shouldn't do it like this! You
should use

  my @list = <*.htm>;

instead.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 29 Sep 2004 05:16:48 -0700
From: mt35@linuxmail.org (mt35)
Subject: Write filename w/ scalar and bareword
Message-Id: <2763816a.0409290416.1ddc5229@posting.google.com>

Hi,

I'm trying to write a file name using a predefined scalar (my $date =
`date "+%m%d%Y"`) and a bareword (snort.tar). Here's the code:


#----------Start Code Block------------
#!/usr/bin/perl

use strict;
use Archive::Tar;

my $tar = Archive::Tar->new;

my $date = `date "+%m%d%Y"`;

chdir "/home/user/perl" or die "$!";

my @tarlst = ("test0", "test1");

$tar->add_files(@tarlst);
$tar->write ("$date test.tar");
#--------End Code Block--------------

However the file written is: 09292004?.snort.tar.gz

My question is why is the question mark being written?...If I add a
"print $date" it comes out fine.

Thanks for your time.


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

Date: 29 Sep 2004 12:46:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <Xns9573594CF34A5asu1cornelledu@132.236.56.8>

mt35@linuxmail.org (mt35) wrote in news:2763816a.0409290416.1ddc5229
@posting.google.com:

> I'm trying to write a file name using a predefined scalar (my $date =
> `date "+%m%d%Y"`) and a bareword (snort.tar). Here's the code:
> 
> 
> #----------Start Code Block------------
> #!/usr/bin/perl
> 
> use strict;
> use Archive::Tar;
> 
> my $tar = Archive::Tar->new;
> 
> my $date = `date "+%m%d%Y"`;

Arrrgh! Why???

To solve your immediate problem, add a 

chomp $date;

after this.
 
> chdir "/home/user/perl" or die "$!";
> 
> my @tarlst = ("test0", "test1");
> 
> $tar->add_files(@tarlst);
> $tar->write ("$date test.tar");
> #--------End Code Block--------------
> 
> However the file written is: 09292004?.snort.tar.gz

That is impossible. You have not run the code you posted. There is no 
mention of 'snort' anywhere between the 'Start Code Block' and 'End Code 
Block' markers. Make sure to post the actual code you run.

> My question is why is the question mark being written?...If I add a
> "print $date" it comes out fine.

Define fine. Is it 'fine' that a newline is written even though you have 
not specified it?

There is no need to spawn an extra process to do something as simple as 
this.

sub filename_prefix_generator {
    my ($sec, $min, $hour, $mday, $mon, $year, undef, undef, undef) =
        localtime time;
    sprintf '%2.2d%2.2d%4.4d_%2.2d%2.2d%2.2d', 
        $mon+1, $mday, $year, $hour, $min, $sec;
}

or, look into POSIX::strftime.

Sinan.


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

Date: Wed, 29 Sep 2004 15:09:25 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <pan.2004.09.29.13.09.21.480851@aursand.no>

On Wed, 29 Sep 2004 12:46:43 +0000, A. Sinan Unur wrote:
> sub filename_prefix_generator {
>     my ($sec, $min, $hour, $mday, $mon, $year, undef, undef, undef) = localtime time;
>     sprintf '%2.2d%2.2d%4.4d_%2.2d%2.2d%2.2d', $mon+1, $mday, $year, $hour, $min, $sec;
> }

First of all, you should also add 1900 to $year.  Secondly, TIMTOWTDI (untested);

  sub filename_prefix_generator {
      my ($sec, $min, $hour, $mday, $mon, $year) = (localtime)[0..5];
      sprintf( '%02d%02d%4d%02d%02d%02d', $mon+1, $mday, $year+1900, $hour, $min, $sec);
  }


-- 
Tore Aursand <tore@aursand.no>
"First get your facts; then you can distort them at your leisure."
 (Mark Twain)


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

Date: Wed, 29 Sep 2004 08:12:48 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <slrnclld6g.huu.tadmc@magna.augustmail.com>

mt35 <mt35@linuxmail.org> wrote:

> I'm trying to write a file name using a predefined scalar (my $date =
> `date "+%m%d%Y"`) and a bareword (snort.tar). Here's the code:
                          ^^^^^^^^

There IS NO bareword anywhere in your code...

A bareword is a word that is not quoted, that is what makes it "bare".


> my $date = `date "+%m%d%Y"`;


Try adding a debugging print() statement here:

   print "date is [$date]\n";


> $tar->write ("$date test.tar");
                      ^^^^^^^^
                      ^^^^^^^^  it is in quotes, so it is not "bare"

> However the file written is: 09292004?.snort.tar.gz


How did it become "snort.tar" instead of "test.tar"?

Where did the dot before the "snort" come from?

What happened to the space that you put into the filename?

Is this truly what your filename looks like?

If so, then you haven't shown us your real code.

If not, then how are we supposed to give an accurate answer
when given inaccurate symptoms?


Have you seen the Posting Guidelines that are posted here frequently?


> My question is why is the question mark being written?


First, there is no question mark being written. I expect *your shell*
is using question mark to represent a newline character?

Second, the question mark is probably actually a newline character,
chomp() it off if you do not want it there.


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


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

Date: 29 Sep 2004 13:16:41 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <Xns95735E61CE952asu1cornelledu@132.236.56.8>

Tore Aursand <tore@aursand.no> wrote in
news:pan.2004.09.29.13.09.21.480851@aursand.no: 

> On Wed, 29 Sep 2004 12:46:43 +0000, A. Sinan Unur wrote:
>> sub filename_prefix_generator {
>>     my ($sec, $min, $hour, $mday, $mon, $year, undef, undef, undef) =
>>     localtime time; sprintf '%2.2d%2.2d%4.4d_%2.2d%2.2d%2.2d',
>>     $mon+1, $mday, $year, $hour, $min, $sec; 
>> }
> 
> First of all, you should also add 1900 to $year.  

My bad ... Hey, aren't you impressed that I remembered to add 1 to the 
month, though :)

> Secondly, TIMTOWTDI (untested); 
> 
>   sub filename_prefix_generator {
>       my ($sec, $min, $hour, $mday, $mon, $year) = (localtime)[0..5];
>       sprintf( '%02d%02d%4d%02d%02d%02d', $mon+1, $mday, $year+1900,
>       $hour, $min, $sec); 
>   }

Was being lazy ... I copied and pasted the my(...) from the perldoc. 
Obviously, an array slice is nicer.

Thanks.

Sinan.


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 7190
***************************************


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