[25697] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7938 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 3 14:06:39 2005

Date: Sun, 3 Apr 2005 11:05:16 -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           Sun, 3 Apr 2005     Volume: 10 Number: 7938

Today's topics:
    Re: accessing arrays in a different sub-routine <nobull@mail.com>
    Re: accessing arrays in a different sub-routine <tadmc@augustmail.com>
    Re: Can perl do this? <nobull@mail.com>
    Re: Database -> Excel <tadmc@augustmail.com>
    Re: difference between two files <tadmc@augustmail.com>
    Re: How to get an external return value? <nobull@mail.com>
    Re: How to get an external return value? <tadmc@augustmail.com>
    Re: Newbie. Use of uninitialized value in print?? <nobull@mail.com>
    Re: Newbie. Use of uninitialized value in print?? axel@white-eagle.invalid.uk
    Re: Newbie. Use of uninitialized value in print?? <matternc@comcast.net>
    Re: Newbie. Use of uninitialized value in print?? <1usa@llenroc.ude.invalid>
    Re: Newbie. Use of uninitialized value in print?? <tadmc@augustmail.com>
    Re: Newbie. Use of uninitialized value in print?? <1usa@llenroc.ude.invalid>
    Re: Stings - textareas in Perl... <joe@inwap.com>
    Re: To change the time stamp format... <dnissimi@hotmail.com>
        To store the output of printf into a variable... clearguy02@yahoo.com
    Re: To store the output of printf into a variable... <jurgenex@hotmail.com>
    Re: Unable to connect to remote host <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 03 Apr 2005 12:09:35 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: accessing arrays in a different sub-routine
Message-Id: <d2oiii$9nv$1@sun3.bham.ac.uk>

Joe Smith wrote:

> erik wrote:
> 
>> I just read that, thanks. That sheds some light. So basically with my
>> example above, and due to it's dynamic nature, the only way I can get
>> this working is a sub-function within a subfunction.
> 
> Use 'my' or 'our' to declare variables.
> Do not re-declare an already declared variable.
> 
> This does not work:
> 
>   my @array;            # File scoped (global) variable
>   sub set_it {
>      my @array = (1,2,3);    # A new, different variable
>   }
>   sub print_it {
>      my @array;            # Yet another different variable
>      print "@array";
>   }
>   set_it; print_it;
> 
> But if you get rid of the 2nd and 3rd 'my', it will work.
> 
> Better yet, use 'our' instead of 'my':
> 
>   sub set_it {
>     our @array;            # Lexical access to long-lived variable
>     @array = (1,2,3);
>   }
>   sub print_it {
>     our @array;            # Access to same long-lived variable
>   }
>   set_it; print_it;

I am a proponent of appropriate use of package variables but this in not 
appropriate.

{
    my @array; # Block scoped variable
    sub set_it {
       @array = (1,2,3);
    }
    sub print_it {
       print "@array";
    }
}

set_it; print_it;



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

Date: Sun, 3 Apr 2005 09:13:59 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: accessing arrays in a different sub-routine
Message-Id: <slrnd4vuh7.jka.tadmc@magna.augustmail.com>

Joe Smith <joe@inwap.com> wrote:

> Do not re-declare an already declared variable.


Unless that is what you meant to do.  <g>


>> I liked this line from the coping with scope.
>> 
>> When to Use my and When to Use local
>> Always use my; never use local.
> 
> I say "Always use my or our; never use local unless forced to."


I prefer to talk about the type of variable to use rather than
the details of how you get the type of variable that you want.

So I like to say:

   Always prefer lexical over package variables, except when you can't.

usually followed by some very brief examples of "when you can't":

   Perl's built-in variables

   Variables that must be visible across file boundaries

   Others too esoteric to mention in an introduction


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


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

Date: Sun, 03 Apr 2005 11:09:27 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Can perl do this?
Message-Id: <d2of1p$81n$2@sun3.bham.ac.uk>


Brian McCauley cut off mid-sentence:

> There is no portable standard for automatic notification of directory 
> updates but if you look in these newsgroups you'll find many discussions 
> of interfacing to the

 ...various OS specific mechanisms.



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

Date: Sun, 3 Apr 2005 10:39:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Database -> Excel
Message-Id: <slrnd503h9.jka.tadmc@magna.augustmail.com>

sigzero@gmail.com <sigzero@gmail.com> wrote:

> That is really close to what I am doing...


What is really close to what you am doing?

Please quote some context when composing a followup, like
everyone else does. Thank you.


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


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

Date: Sun, 3 Apr 2005 11:22:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: difference between two files
Message-Id: <slrnd5062u.jsi.tadmc@magna.augustmail.com>

xhoster@gmail.com <xhoster@gmail.com> wrote:

> if every one-liner I have ever written was saved to
> disk as a four-liner, there would be so stinking many of them I would never
> be able to find the one I wanted when I wanted it again.


I have that problem even with > 4 LOC programs.

So I always put a 2nd line formatted like this:

   # progname - one line description of what progname does

into all of my programs.


Then, when I need to find some lost program, I just run this:

----------------------------------
#!/usr/bin/perl
# perl_program_index - make an index of all of my Perl programs
use warnings;
use strict;
use File::Find;

@ARGV = '.' unless @ARGV;     # default to current directory

find \&perl_programs, @ARGV;


sub perl_programs {
   return unless -f and -e and -T; # consider only executable text files

   open PROG, $_ or die "could not open '$_'  $!";
   return unless defined(my $shebang = <PROG>);
   return unless defined(my $comment = <PROG>);
   close PROG;

   return unless $shebang =~ /^#!.*perl/;         # not a perl program
   return unless $comment =~ /^#\s*(\w+) - (.*)/; # not properly commented

   print "$2\n   $File::Find::name\n\n";
}
----------------------------------


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


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

Date: Sun, 03 Apr 2005 11:25:33 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to get an external return value?
Message-Id: <d2og00$8as$1@sun3.bham.ac.uk>



topple wrote:

> My books don't address the question.

Your problem is that you are not partitioning your problem correctly. 
Learning to partition problems is (possibly) the most importand skill in 
programming.

>  Lots of stuff about using backticks
> to call system functions and getting return values, but how do I return a
> value from one of my own external routines.

The external routines are not Perl.  Or rather they could be Perl but 
that would only be a co-incidence.  The backticks capture the standard 
output stream of another program.  The question of how to emit stuff to 
to that standard output stream is a question about the language in which 
the other program is written.

Now, if the other program also happens to be written in Perl this 
becomes the question  how to I get a Perl program to emit output to 
STDOUT.  The important thing to realise is that his question is 
completely unrelated to the question about Perl capturing the STDOUT of 
another program.

If you don't know how to get Perl to emit standard output then perhaps 
you should study the following program (which you may have seen before):

#!/usr/bin/perl
use strict;
use warnings;

print "Hello world!\n";
__END__



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

Date: Sun, 3 Apr 2005 10:21:01 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to get an external return value?
Message-Id: <slrnd502et.jka.tadmc@magna.augustmail.com>

topple <nope@nowhere.com> wrote:
>> 
>> backticks don't provide return values, they
>> merely capture the output of the external program. 


>> BTW: Why aren't you simply consulting the documentation that comes with
>> Perl?
>> 
> 
> Thanks.  I realise that the question may be rather odd (ok, stupid).  


Adding that parenthetical is extraordinary for...


> I am
> a hobby programmer.  


 ... a hobbiest programmer.

The overwhelming majority of such programmers here display
a baffling tendency to object to advice from somone who's 
very livelihood depends on your hobby.

Congratulations on your rare Good Attitude! It is refreshing.
You will learn a lot.


> Never made a nickle on it and like it that way - no
> pressure, no deadlines. 


Yes, we could already tell that you were not formally trained.

Since you appear genuinely interested in learning, here is
how we could tell.  :-)

No competent programmer would have conflated these 3 concepts,
as appears to have happened in this thread:

   the "return value" of a subroutine

   the "output" of a program

   the "exit status" of a program

If you're not clear on the distinctions between them, post
another question about them.


> Perl is a whole lot different.  


But it is not at all different with regard to those 3 concepts.

The root cause of your problem was not related to Perl, it
was related to general Computer Science. Finding the answer
gets a whole lot easier once you know the right search term.

ie. I think you meant to ask for "output" rather than "return value".

Once you know that a program's "output" is what you want, it
becomes irrelevant whether that program was written in Perl or
in some other programming language.

And once you realize that your called Perl program is just
another "external" (program|command), the Perl FAQ answers
your question:

   perldoc -q external

       How can I capture STDERR from an external command?

   ... Backticks ... read ... the STDOUT of your command.


> Just the backtick method of calling something took hours of searching
> before I even knew it existed.


Gak!

Tens of thousands of people have come before you in learning Perl.

Issues that have tripped them up over and over (and their solutions)
have been collected together into Perl's Frequently Asked Questions.

Want to spend lots of time repeating common mistakes, or solve
the problem in less than 5 minutes?

If the former, code away!

If the later, check (or even read end-to-end) the Perl FAQ.


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


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

Date: Sun, 03 Apr 2005 11:52:31 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <d2ohii$95q$1@sun3.bham.ac.uk>



Jon Anderson wrote:

> Im having problems getting some Perl code to work (im a programming
> newbie).

Have you considered any of the self-help solutions that the regulars 
here _always_ tell _all_ newbies they should try before asking others 
for help?

Do you realise that not doing so is saying in no uncertain terms that 
you value the time of the people you are asking for help considerably 
less than you value your own?

Please read the posting guidelines.

> The aim of the code is to read certain text from a file,
> print it to screen then allow the user to make a choice based on that
> output. Well, that's the aim so far anyway (im about half way through
> the code). Ive been stuck on this however. Im getting the error "Use
> of uninitialized value in print at... line 26, <STDIN> line 1."

> Ive spent most of the day trying to work out what's wrong,

You see, false lazyness doesn't pay - even in the relatively short term 
let alone the medium or long term.

>The code is,

Not declaring all variables in the smallest applicable lexical scope. 
(Can you please explain how we could have been any more forceful about 
the importance of doing this).

Not using strict (to detect when you've forgotten to declare a variable).

Not indented to make it readable.

Anyhow the following looks odd...

> $prices2 = @raw_data;
> @prices1to5 = split (/:/, $prices2);

Since $prices2 is the number of elements in the array @raw_data it will 
be a number and it does not therefore make sense to split it on /:/.

> I cant pick up the error despite going over it many times & trying a
> number of things

Have you tried inserting diagnostic print()s to see if variables contain 
what you expect?  This is always a good idea.



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

Date: Sun, 03 Apr 2005 06:11:22 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <Y6Cdnecbe8rHUtLfRVn-tw@adelphia.com>

Jon Anderson <five421@fastmail.fm> wrote:
> Im having problems getting some Perl code to work (im a programming
> newbie). The aim of the code is to read certain text from a file,
> print it to screen then allow the user to make a choice based on that
> output. Well, that's the aim so far anyway (im about half way through
> the code). Ive been stuck on this however. Im getting the error "Use
> of uninitialized value in print at... line 26, <STDIN> line 1."

The warning indicates that you are trying to print out a value from a
variable which has not been initialised - i.e. no value has been
assigned to that variable.

> Ive spent most of the day trying to work out what's wrong, but have
> come up empty handed. The code is,

> print "\n";
> $prices2 = @raw_data;
> @prices1to5 = split (/:/, $prices2);

You have assigned the length of @raw_data to $prices2.
It makes no sense to try to split this numb er.

The array @prices1to5 will contain one item $prices1to5[0] which is set
to whatever the length of @raw_data is.

> print "Please enter the item to be purchased..\n\n";
> chomp($selectitem = <STDIN>);
> if($selectitem == 1)
> {
> print "\n";
> print "You selected item 1, which sells for\n";
> print  $prices1to5[1];

Therefore as $prices1to5[1] has not been assigned a value, the warning
is generated.

May I suggest for general readability that you indent statements within
loops. See:

	perldoc perlstyle

Axel




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

Date: Sun, 03 Apr 2005 08:37:15 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <BPWdnVaR49jmftLfRVn-oQ@comcast.com>

Jon Anderson wrote:

> Hi,
> 
> Im having problems getting some Perl code to work (im a programming
> newbie). The aim of the code is to read certain text from a file,
> print it to screen then allow the user to make a choice based on that
> output. Well, that's the aim so far anyway (im about half way through
> the code). Ive been stuck on this however. Im getting the error "Use
> of uninitialized value in print at... line 26, <STDIN> line 1."
> Ive spent most of the day trying to work out what's wrong, but have
> come up empty handed. The code is,
> 
> $lnum = 0;
> open (INPUT, "file.txt") or die "Error, can't find file\n";
> @raw_data=<INPUT>;
> close(INPUT);
> #Print to screen the pricelist in the text file
> foreach $price (@raw_data)
> {
> @pricelist = split (/:/, $price);
> print "$lnum" . " " . "$pricelist[1]\n" if @pricelist != 1;
> $lnum ++;
> }
> print "\n";
> $prices2 = @raw_data;
> @prices1to5 = split (/:/, $prices2);
> print "Please enter the item to be purchased..\n\n";
> chomp($selectitem = <STDIN>);
> if($selectitem == 1)
> {
> print "\n";
> print "You selected item 1, which sells for\n";
> print  $prices1to5[1];
> $item = 1;
> }
> elsif($selectitem == 2)
> {
> print "\n";
> print "You selected item 2, which sells for\n";
> print $prices1to5[2];
> $item = 2;
> }
> elsif($selectitem == 3)
> {
> print "\n";
> print "You selected item 3, which sells for\n";
> print $prices1to5[3];
> $item = 3;
> }
> elsif($selectitem == 4)
> {
> print "\n";
> print "You selected item 4, which sells for\n";
> print $prices1to5[4];
> $item = 4;
> }
> elsif($selectitem == 5)
> {
> print "\n";
> print "You selected item 5, which sells for\n";
> print $prices1to5[5];
> $item = 5;
> }
> else
> {
> print "\n";
> print "Invalid item selection! No such item\n";
> }
> 
> 
> ---
> 
> The code at line 26 is
> 
> 18  $prices2 = @raw_data;
> 19  @prices1to5 = split (/:/, $prices2);
> 20  print "Please enter the item to be purchased..\n\n";
> 21  chomp($selectitem = <STDIN>);
> 22  if($selectitem == 1)
> 23  {
> 24  print "\n";
> 25  print "You selected item 1, which sells for\n";
> 26  print  $prices1to5[1];
> 
> ---
> 
> I cant pick up the error despite going over it many times & trying a
> number of things after looking for answers online. Any help would be
> greatly appreciated :)

Well, first of all, it seems like it would be so much simpler to say:

print "You selected item $selectitem, which sells for\n";
print $prices1to5[$selectitem];

rather than all those ifs...

Second of all, you're getting that warning (not error) because 
$prices1to5[1] isn't defined, that simple.  $prices2 contains
a single number; how many elements are in @raw_data.  You then
split it on :.  Since there are no :s in $prices2, the number
goes in @prices1to5[0] (you *are* aware that Perl arrays start
at 0, right?).  Any other element comes up as undefined.
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Sun, 03 Apr 2005 13:09:54 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <Xns962D5D3BE77D6asu1cornelledu@127.0.0.1>

five421@fastmail.fm (Jon Anderson) wrote in 
news:71322843.0504030136.2e4d01e1@posting.google.com:

> Im having problems getting some Perl code to work (im a programming
> newbie). 

You should ask for all the help the perl can give you.

 ...

> Im getting the error "Use of uninitialized value in print at... 
> line 26, <STDIN> line 1."

FYI, that is a warning, not an error.

> Ive spent most of the day trying to work out what's wrong, but have
> come up empty handed. The code is,

You should have

use strict;
use warnings;

and possibly

use diagnostics;

> $lnum = 0;

my $lnum = 0;

Base on the name of the variable, I am assuming this has to do with 
counting line numbers in the file. Perl has a builtin variable that does 
this for you.

> open (INPUT, "file.txt") or die "Error, can't find file\n";

Unless there is a specific reason to do otherwise, prefer the three 
argument form of open using lexical filehandles:

open my $input, '<', 'file.txt' 
    	or die "Error opening file.txt: $!";

open can fail even when the file can be found. Use $! to convey the 
reason open failed.

> @raw_data=<INPUT>;

No need to slurp the entire file.

> close(INPUT);
> #Print to screen the pricelist in the text file
> foreach $price (@raw_data)

This is misleading. @rawdata contains lines from the file

> @pricelist = split (/:/, $price);

which seem to contain entries such as

128 MB Flash Drive: $14.99

> print "$lnum" . " " . "$pricelist[1]\n" if @pricelist != 1;
> $lnum ++;
> }
> print "\n";
> $prices2 = @raw_data;

As others have pointed out, assigning the number of lines in the 
original file to $prices2

> @prices1to5 = split (/:/, $prices2);

and splitting that causes the warning to be emitted.

> print "Please enter the item to be purchased..\n\n";
> chomp($selectitem = <STDIN>);
> if($selectitem == 1)

Whenever you see tedious repetition like this, you should remember that 
you are dealing with a computer program. The fact that the program needs 
to repeat things does mean that the *programmer* needs to repeat them as 
well.

> I cant pick up the error despite going over it many times & trying a
> number of things after looking for answers online. 

Did your online reading include the posting guidelines for this group? 
If yes, why did you choose not to follow them? If not, why not?

> Any help would be greatly appreciated :)

Here is one way to read the first five description/price information 
from a file, display the information as a menu, and get the user's 
input. It would be most useful to you to study each of the features used 
(consult the documentation that comes with Perl. To get an idea of what 
information is available, you can use perldoc perltoc.

Warnings: The script below ignores various issues such as the cases 
where there are fewer than expected entries, how to choose among more 
than 9 items etc.

#! /usr/bin/perl

use strict;
use warnings;

use constant ITEMS_TO_SHOW => 5;

my @menu;

while(<DATA>) {
    last if $. > ITEMS_TO_SHOW;
    chomp;
    last unless length $_;
    my ($desc, $price) = split /:/;
    push @menu, { desc => $desc, price => $price };
    printf "[ %d ] : %s (%s)\n", $., $desc, $price;
}

$| = 1;
print "Select an item: ";
my $item = <STDIN>;
chomp($item);

unless($item >= 1 and $item <= ITEMS_TO_SHOW) {
    die "Item number out of range\n";
}

print "You selected item $item whose price is: ",
    $menu[$item - 1]->{price}, "\n";

__DATA__
128 MB Flash Drive : $14.99
Bahamas Vacation : $999.99
10/100/1000 NIC : $19.99
Pizza : $11
Soda : $1.50
Mazda Protege: $14999
Movie Ticket: $6.50




-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 3 Apr 2005 10:35:19 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <slrnd5039n.jka.tadmc@magna.augustmail.com>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> five421@fastmail.fm (Jon Anderson) wrote in 
> news:71322843.0504030136.2e4d01e1@posting.google.com:

>> Im getting the error "Use of uninitialized value in print at... 
>> line 26, <STDIN> line 1."
> 
> FYI, that is a warning, not an error.


Said with a non-petty phrasing!

Golly, I'm feeling all warm and fuzzy here at the clpmisc lovefest.

<g>


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


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

Date: Sun, 03 Apr 2005 16:34:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <Xns962D7FE9DC71Fasu1cornelledu@127.0.0.1>

Tad McClellan <tadmc@augustmail.com> wrote in 
news:slrnd5039n.jka.tadmc@magna.augustmail.com:

> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>> five421@fastmail.fm (Jon Anderson) wrote in 
>> news:71322843.0504030136.2e4d01e1@posting.google.com:
> 
>>> Im getting the error "Use of uninitialized value in print at... 
>>> line 26, <STDIN> line 1."
>> 
>> FYI, that is a warning, not an error.
> 
> 
> Said with a non-petty phrasing!
> 
> Golly, I'm feeling all warm and fuzzy here at the clpmisc lovefest.
> 
> <g>

I wish I had seen your compliment before I went off on a rant in another 
message. I might not have done it. I'll try to cancel that one.

Sigh!

Thanks, BTW.

Sinan.

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 03 Apr 2005 03:07:35 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <e6ydnekU2oD2XdLfRVn-1Q@comcast.com>

joesplink wrote:
>"Why don't these 2 snippets send the same output to the server?"

Don't you mean "from the server"?

> "exactly what do these scripts send to the server?"

Send to the _browser_.

The perl answer to that is 'use LWP::Simple;'.
	-Joe


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

Date: Sun, 3 Apr 2005 14:56:39 +0300
From: "Doron Nissimi" <dnissimi@hotmail.com>
Subject: Re: To change the time stamp format...
Message-Id: <d2olls$pfp$1@news2.netvision.net.il>


<clearguy02@yahoo.com> wrote in message
news:1112461264.799057.147850@f14g2000cwb.googlegroups.com...
> Hi experts,
>
> I need a function in my perl program that converts the given time stamp
> to a specific time stamp format.
>
> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>
> Can some one tell me how to do this?
>
> Thanks,
> John
>

Try Date::Manip
Simple, and powerful.




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

Date: 3 Apr 2005 08:56:26 -0700
From: clearguy02@yahoo.com
Subject: To store the output of printf into a variable...
Message-Id: <1112543786.277123.214150@f14g2000cwb.googlegroups.com>

Hi experts,

I got help earlier from here on a scrit and the final script looks as
follows. My goal is to store the new date into a vairable and use it
some where else in the perl program:

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

$date = '15-Mar-04.01:03';
%months = qw(Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct
10 Nov 11 Dec 12);
$month_lookup = join '|', keys %months;
if ( $date =~ /(\d+)-($month_lookup)-(\d+)\.(\d+):(\d+)/ )
 {
  printf "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2}, $1, $4,
$5;
 }
-------------------------------

Now, instead of printing the date onto the cmd screen, I want to store
it into a variable.

When I do the following, it doesn't work:
$finalDate = printf "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2},
$1, $4, $5;
And $finalDate doesn't capture the date.

I also tried the below one:
printf $finalDate "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2},
$1, $4, $5;

Can you pl. tell me how I can store the date into a variable instead of
printing it onto the screen?

Thanks,
John



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

Date: Sun, 03 Apr 2005 16:17:38 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: To store the output of printf into a variable...
Message-Id: <CGU3e.1688$%b1.39@trnddc08>

clearguy02@yahoo.com wrote:

> [Subject:] To store the output of printf into a variable...

perldoc -f sprintf

jue 




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

Date: Sun, 03 Apr 2005 11:07:03 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unable to connect to remote host
Message-Id: <d2oeta$81n$1@sun3.bham.ac.uk>



sri wrote:

> I insterted $^E alongside $!. It gave me much more info....
> 
> Error is "The requested service provider could not be loaded or
> initialized" . I googled this error and found that its something to do
> with winsock. I could not find a solution though. Do you have any
> suggestion?

Sounds most likely to be some subtle problem with the Windows security 
model.  This is not something I know much about.



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

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


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