Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

perl-beginner · Perl Beginners Mailing List

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 3761
  • Category: Perl
  • Founded: Aug 2, 1998
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

Advanced
Messages Help
Messages 735 - 764 of 27470   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#735 From: Tom Barron <tbarron@...>
Date: Fri Sep 1, 2000 1:34 pm
Subject: Re: [PBML] Re: Memory Management
tbarron@...
Send Email Send Email
 
sloan.scott@... wrote:
> ...
> How about tracking how much memory is in use?  When it reaches a
> certain limit then flag on it.  Is that possible?

What do you mean by "flag on it"?  I'm not sure how you'd go about
tracking how much memory is in use.

Tom

#736 From: bob jacobson <bjacobson@...>
Date: Fri Sep 1, 2000 8:43 pm
Subject: Time question
bjacobson@...
Send Email Send Email
 
Can anyone tell me of a way to determine the time value or # of seconds of
anydate?  For example, how can I find the seconds for July 26, 2000 at 11:04
am.  Having this value will allow me to use the localtime function to get
needed info such as the day of the week for this date.  Or maybe is there
another way of doing this as opposed to using localtime?  TIA!

Bob Jacobson
Access Cash International
Email:  bjacobson@...

#737 From: Tom Barron <tbarron@...>
Date: Fri Sep 1, 2000 9:57 pm
Subject: Re: [PBML] Time question
tbarron@...
Send Email Send Email
 
bob jacobson wrote:
> Can anyone tell me of a way to determine the time value or # of seconds of
> anydate?  For example, how can I find the seconds for July 26, 2000 at 11:04
> am.  Having this value will allow me to use the localtime function to get
> needed info such as the day of the week for this date.  Or maybe is there
> another way of doing this as opposed to using localtime?  TIA!

use POSIX;

$sec = POSIX::mktime(0,4,11,26,6,100);  # July 26, 2000 11:04 a.m.
print "sec = $sec\n";
print join(" ", localtime($sec)), "\n";

Note that July is 6 (jan = 0, feb = 1, etc.) and 2000 is 100 (1999 = 99,
2001 = 101, etc.).

Also beware of daylight savings time adjustments.  When I run the code
above on my machine, I get:

   DB<4> $sec = POSIX::mktime(0,4,11,26,6,100);  # July 26, 2000 11:04
a.m.

   DB<5> print "sec = $sec\n";
sec = 964631040

   DB<6> print join(" ", localtime($sec)), "\n";
0 4 12 26 6 100 3 207 1
     ^^
      DST adjusted hour

hth...
Tom

#738 From: bob jacobson <bjacobson@...>
Date: Fri Sep 1, 2000 10:16 pm
Subject: RE: [PBML] Time question
bjacobson@...
Send Email Send Email
 
Thank you very much, this is exactly what I needed!


-----Original Message-----
From: Tom Barron [mailto:tbarron@...]
Sent: Friday, September 01, 2000 4:58 PM
To: perl-beginner@egroups.com
Subject: Re: [PBML] Time question



bob jacobson wrote:
> Can anyone tell me of a way to determine the time value or # of seconds of
> anydate?  For example, how can I find the seconds for July 26, 2000 at
11:04
> am.  Having this value will allow me to use the localtime function to get
> needed info such as the day of the week for this date.  Or maybe is there
> another way of doing this as opposed to using localtime?  TIA!

use POSIX;

$sec = POSIX::mktime(0,4,11,26,6,100);  # July 26, 2000 11:04 a.m.
print "sec = $sec\n";
print join(" ", localtime($sec)), "\n";

Note that July is 6 (jan = 0, feb = 1, etc.) and 2000 is 100 (1999 = 99,
2001 = 101, etc.).

Also beware of daylight savings time adjustments.  When I run the code
above on my machine, I get:

   DB<4> $sec = POSIX::mktime(0,4,11,26,6,100);  # July 26, 2000 11:04
a.m.

   DB<5> print "sec = $sec\n";
sec = 964631040

   DB<6> print join(" ", localtime($sec)), "\n";
0 4 12 26 6 100 3 207 1
     ^^
      DST adjusted hour

hth...
Tom

#739 From: joach@...
Date: Sun Sep 3, 2000 10:10 pm
Subject: Help with date format
joach@...
Send Email Send Email
 
I have been working with file which have the date as 20000903   and I
wish then to read 03092000
I would think that this would have to be split and  YYYY=4 fields from
the left   ..... and something similar for the MM and DD....... this is
the format I would like to use..... because it would allow edits of
other data like 2000-09-03   and 2000 09 03  or 2000/09/03  into a
format I could use.

My data looks like

200000830,5151,5645,874.6547
200000831,987,4568,5557,1542
200000901,6546,1695,6515,5145
200000902,4555,6546,654,5454
200000903,6544,616,358,6854

I would like to use it in a small script as below......

#!/usr/bin/perl -w
use strict;

my $infile  = shift;
my $outfile = shift;

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

while (<IN>) {
     chomp;

#{ please enter sutiable lines to fit into this space }

close (IN);
close (OUT);

__END__


TIA

John

#740 From: Tom Barron <tbarron@...>
Date: Sun Sep 3, 2000 10:20 pm
Subject: Re: [PBML] Help with date format
tbarron@...
Send Email Send Email
 
Here's one way...

joach@... wrote:
> ...
> while (<IN>) {
>     chomp;

     @data = split(/,/, $_);
     ($year,$month,$day) = ($data[0] =~ /(....)[ /-]?(..)[ /-]?(..)/);
     $dmy = $day . $month . $year;

> close (IN);
> close (OUT);

Tom

#741 From: "Maisha Walker" <maisha@...>
Date: Sun Sep 3, 2000 10:42 pm
Subject: Re: [PBML] Help with date format
maisha@...
Send Email Send Email
 
Hi Tom,

Could you explain how this:
=~ /(....)[ /-]?(..)[ /-]?(..)/);

actively splits this data:
200000830

  into three pieces that can be picked up by variables?

I recognize that it's a regular expression but doesn't this just *find* the
data?  I thought you would need to use a substring to actually split it.

Thanks!
Maisha

-----Original Message-----
From: Tom Barron <tbarron@...>

Here's one way...

joach@... wrote:
> ...
> while (<IN>) {
>     chomp;

     @data = split(/,/, $_);
     ($year,$month,$day) = ($data[0] =~ /(....)[ /-]?(..)[ /-]?(..)/);
     $dmy = $day . $month . $year;

> close (IN);
> close (OUT);

Tom

#742 From: joach@...
Date: Sun Sep 3, 2000 11:39 pm
Subject: Re: [PBML] Help with date format
joach@...
Send Email Send Email
 
OK.... ran it through the debugger and it says there are errors in line #14
not just one but several.....
What I am trying to do is reverse the date order in the first field in the
file presently the data begins each line with 20000801 through to 20000903
and I would like the field to read in this order   03092000...... it would
be nice if we could break down the string and then write to file....


#!/usr/bin/perl -w
use strict;

my $infile  = shift;
my $outfile = shift;

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

while (<IN>) {
     chomp;
     my @data = split(/,/, $_);
         ($year,$month,$day) = (@data[0] =~ /(....)[ /-]?(..)[ /-]?(..)/);
     $dmy = $day . $month . $year;
close (IN);
close (OUT);

__END__


John

#743 From: Tom Barron <tbarron@...>
Date: Sun Sep 3, 2000 11:39 pm
Subject: Re: [PBML] Help with date format
tbarron@...
Send Email Send Email
 
Maisha Walker wrote:
> Hi Tom,
>
> Could you explain how this:
> =~ /(....)[ /-]?(..)[ /-]?(..)/);
>
> actively splits this data:
> 200000830
>
>  into three pieces that can be picked up by variables?
>
> I recognize that it's a regular expression but doesn't this just *find* the
> data?  I thought you would need to use a substring to actually split it.
>
> Thanks!

The secret ingredient is the parentheses.  Ordinarily, the return value
of =~ is 1 or 0, indicating whether the match was successful or not.
F'rinstance,


   DB<1> p "abcdef" =~ /./
1

However, if the regexp contains parentheses, the return value is a list
of the matched parenthesized subexpressions:

   DB<2> p "abcdef" =~ /(.)/
a

or

   DB<4> p join(" ", "abcdef" =~ /(.)(.)(.)/)
a b c

Since the expression

    "$date[0] =~ /(....)[ /-]?(..)[ /-]?(..)/"

returns a list, we can assign that list to another list, like, say,

    ($year, $month, $day)

hth...
Tom

#744 From: Tom Barron <tbarron@...>
Date: Sun Sep 3, 2000 11:41 pm
Subject: Re: [PBML] Help with date format
tbarron@...
Send Email Send Email
 
joach@... wrote:
> OK.... ran it through the debugger and it says there are errors in line #14
> not just one but several.....

You're missing a closing brace.  I've marked it below.

> What I am trying to do is reverse the date order in the first field in the
> file presently the data begins each line with 20000801 through to 20000903
> and I would like the field to read in this order   03092000...... it would
> be nice if we could break down the string and then write to file....
>
> #!/usr/bin/perl -w
> use strict;
>
> my $infile  = shift;
> my $outfile = shift;
>
> open (IN, $infile)     || die "can't open $infile: $!";
> open (OUT, ">$outfile")|| die "can't open $outfile: $!";
>
> while (<IN>) {
>     chomp;
>     my @data = split(/,/, $_);
>         ($year,$month,$day) = (@data[0] =~ /(....)[ /-]?(..)[ /-]?(..)/);
>     $dmy = $day . $month . $year;

You need a "}" here.

> close (IN);
> close (OUT);

#745 From: Andrew Johnson <andrew-johnson@...>
Date: Mon Sep 4, 2000 12:44 am
Subject: Re: [PBML] Help with date format
andrew-johnson@...
Send Email Send Email
 
! OK.... ran it through the debugger and it says there are errors in line #14
! not just one but several.....

You are missing the closing brace on your while loop, and you are
introducing new variables without using my() (which you should be
doing since you are using 'strict' ... which is a good thing). You
are also using '/' in the character class and as the regex delimiter.

Here's a slightly different version of Tom's that doesn't require
the extra variables -- it will also simply leave the date as it is
if it doesn't match the regex (we are using s<><> rather than s///):

     while (<IN>) {
         chomp;
         my @data = split /,/;
         $data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>;
         print OUT join(',',@data),"\n";
     }


Is that what you intended?

regards,
andrew

--
Andrew L. Johnson   http://members.home.net/perl-epwp/
       It may be that your sole purpose in life is simply to
       serve as a warning to others.

#746 From: joach@...
Date: Mon Sep 4, 2000 2:02 am
Subject: Re: [PBML] Help with date format
joach@...
Send Email Send Email
 
>
>
>     while (<IN>) {
>         chomp;
>         my @data = split /,/;
>         $data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>;
>         print OUT join(',',@data),"\n";
>     }
>
> Is that what you intended?

YES........!!!

This copy of the script come through without errors........ and does the job
very
nicely.
This sort of format does not appear in the texts I've read....or ....maybe just
like now I$data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>; still don't
understand it...... would you have the time to document what is happening in
line

$data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>;     I would like to
apply what I'm learning here to other date formats like 2000-09-03   or
2000/09/03........

Thank you for taking the time to post .....much appreciate it

John

#747 From: Greg Webster <greg@...>
Date: Mon Sep 4, 2000 2:23 am
Subject: Re: [PBML] Help with date format
greg@...
Send Email Send Email
 
Personally...

To convert 20000803 (and be able to do cool things with the values
individually), I'd do something like the following:

$wholedate = '20000803';
@alldigits = split(//, $wholedate);
$year = join('', @alldigits[0..3]);
$month = join('', @alldigits[4..5]);
$day = join('', @alldigits[6..7]);

print "Year: $year : Month: $month : Day: $day\n";

Then you can easily deal with all of the dates in bits. There's really no
reason to complicate matters here.

BTW, I'm sure is Awk type formats and $1, $2, $3 etc...this could be simplified
further.

Greg

--
< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
  |   |  |  GREG WEBSTER - greg@...   |  |   |  |
<_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>

#748 From: Andrew Johnson <andrew-johnson@...>
Date: Mon Sep 4, 2000 2:31 am
Subject: Re: [PBML] Help with date format
andrew-johnson@...
Send Email Send Email
 
! the time to document what is happening in line
!
! $data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>;

Firstly, you do not have to use / as the delimiters for m// and s///,
you are free to use other single characters -- common choices are:
m#pattern# and m|pattern| (same for s### and s|||) -- also, you can
use paired delimiters like: m{pattern} and m<pattern> (or s{}{}, and
s<><>). Using alternate delimiters makes things easier when your
pattern contains / characters.

Here is the regex with comments:

$data[0] =~ s<
                ^        # match start of string
                (        # open $1 capture parens
                 \d{4}   # grab 4 digits into $1
                )        # close $1
                [ /-]?   # optionally match a space, slash, or dash
                (        # open $2 capture
                 \d\d    # grab 2 digits into $2
                )        # close $2
                [ /-]?   # optionally match a space, slash, or dash
                (        # open $3 capture
                 \d\d    # grab 2 digits into $3
                )        # close $3
                $        # match end of string
               >
               <$3$2$1>x;# replace with "$3$2$1", the 'x' modifier
                         # allows these comments


! I would like to apply what I'm learning here to other date formats
! like 2000-09-03 or 2000/09/03........

As you can see, the above already handles these formats by allowing
for an optional space, slash, or dash between the groups -- this was
inherent in Tom's posted reply.

Other resources for learning about regular expressions are:

     perldoc perlre

Mark Kvale has a couple of regex tutorials available:

     http://keck.ucsf.edu/~kvale/perlrequick.pod
     http://keck.ucsf.edu/~kvale/perlretut.pod

The first is an introductory tutorial, the latter covers some more
advanced features -- I also have one similar to Kvale's advanced one
that I mostly finished before hearing about his (if I knew he was
doing it I could have spent my time doing other things :-). You can
find it at:

     http://members.home.net/andrew-johnson/perl/regextut.pod

Lastly, I might as well mention that one of the two sample chapters
for my book is on regular expressions and might be of use (it is a
PDF file, free) -- grab chapter 10 at:

     http://www.manning.com/Johnson/Chapters.html

Hope it helps.

regards,
andrew

--
Andrew L. Johnson   http://members.home.net/perl-epwp/
       Doing linear scans over an associative array is like
       trying to club someone to death with a loaded Uzi.
           -- Larry Wall

#749 From: joach@...
Date: Mon Sep 4, 2000 2:48 am
Subject: Re: [PBML] Help with date format
joach@...
Send Email Send Email
 
Thank you for the detailed explanation ...... and the reading material....
There is more to the perl than one thinks....I like the way i covers the
space, slash, or dash .....all options are covered.

John


> $data[0] =~ s<
>                ^        # match start of string
>                (        # open $1 capture parens
>                 \d{4}   # grab 4 digits into $1
>                )        # close $1
>                [ /-]?   # optionally match a space, slash, or dash
>                (        # open $2 capture
>                 \d\d    # grab 2 digits into $2
>                )        # close $2
>                [ /-]?   # optionally match a space, slash, or dash
>                (        # open $3 capture
>                 \d\d    # grab 2 digits into $3
>                )        # close $3
>                $        # match end of string
>               >
>               <$3$2$1>x;# replace with "$3$2$1", the 'x' modifier
>                         # allows these comments
>
> ! I would like to apply what I'm learning here to other date formats
> ! like 2000-09-03 or 2000/09/03........
>

#750 From: Luke Metcalfe <luke@...>
Date: Mon Sep 4, 2000 6:08 am
Subject: Timeouts in requesting pages with LWP
luke@...
Send Email Send Email
 

I'm pulling my hair out over this one:



use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
 
my $ua = new LWP::UserAgent;
$ua->use_alarm(0) ;   # I've tried this at 1 too.
$ua->timeout(1);
my $request = new HTTP::Request('GET', $ARGV[0]);
my $response = $ua->request($request);
if ($response->is_success) {
     print $response->content;
} else {
     print $response->error_as_HTML;
}


Gets the page ok, but doesn't timeout early if it's an invalid server..




Luke Metcalfe
Sydney Australia

icq  684965
mobile  0417 677 249
email  luke@...


#751 From: joach@...
Date: Mon Sep 4, 2000 7:34 am
Subject: Help Reversing Data
joach@...
Send Email Send Email
 
Well I am getting better but still not there yet.    What I am trying to
do is reverse the Data..... and add a Header......Reverses just
fine..... and adds the Header.   What I need is a line feed added behind
the header so that the data does not start at the end of the
Header...... I would like it to start the data the line after the
Header.

TIA

John
-------------------------------------------------

#!/usr/bin/perl -w
use strict;

my $infile  = shift;
my $outfile = shift;
my $header='"My Header"';
  print "Reversing date sequence\n";

  open (IN,$infile) || die "Could not open $infile $!";
  open (OUT, ">$outfile")|| die "can't open $outfile: $!";
  my @data= (<IN>);

  push @data,$header;

  @data = reverse @data;

  print OUT @data;
  close IN;
  close OUT;
__End__
  ----------------------

#752 From: "Maisha Walker" <maisha@...>
Date: Mon Sep 4, 2000 1:37 pm
Subject: Re: [PBML] Help with date format
maisha@...
Send Email Send Email
 
Andrew - that was a beautiful and suprisingly simple explanation of what was
going on in that regex.

Thank you!!

maisha
-----Original Message-----
From: Andrew Johnson <andrew-johnson@...>


! the time to document what is happening in line
!
! $data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>;

Firstly, you do not have to use / as the delimiters for m// and s///,
you are free to use other single characters -- common choices are:
m#pattern# and m|pattern| (same for s### and s|||) -- also, you can
use paired delimiters like: m{pattern} and m<pattern> (or s{}{}, and
s<><>). Using alternate delimiters makes things easier when your
pattern contains / characters.

Here is the regex with comments:

$data[0] =~ s<
                ^        # match start of string
                (        # open $1 capture parens
                 \d{4}   # grab 4 digits into $1
                )        # close $1
                [ /-]?   # optionally match a space, slash, or dash
                (        # open $2 capture
                 \d\d    # grab 2 digits into $2
                )        # close $2
                [ /-]?   # optionally match a space, slash, or dash
                (        # open $3 capture
                 \d\d    # grab 2 digits into $3
                )        # close $3
                $        # match end of string
               >
               <$3$2$1>x;# replace with "$3$2$1", the 'x' modifier
                         # allows these comments


! I would like to apply what I'm learning here to other date formats
! like 2000-09-03 or 2000/09/03........

As you can see, the above already handles these formats by allowing
for an optional space, slash, or dash between the groups -- this was
inherent in Tom's posted reply.

Other resources for learning about regular expressions are:

     perldoc perlre

Mark Kvale has a couple of regex tutorials available:

     http://keck.ucsf.edu/~kvale/perlrequick.pod
     http://keck.ucsf.edu/~kvale/perlretut.pod

The first is an introductory tutorial, the latter covers some more
advanced features -- I also have one similar to Kvale's advanced one
that I mostly finished before hearing about his (if I knew he was
doing it I could have spent my time doing other things :-). You can
find it at:

     http://members.home.net/andrew-johnson/perl/regextut.pod

Lastly, I might as well mention that one of the two sample chapters
for my book is on regular expressions and might be of use (it is a
PDF file, free) -- grab chapter 10 at:

     http://www.manning.com/Johnson/Chapters.html

Hope it helps.

regards,
andrew

--
Andrew L. Johnson   http://members.home.net/perl-epwp/
       Doing linear scans over an associative array is like
       trying to club someone to death with a loaded Uzi.
           -- Larry Wall

#753 From: "Maisha Walker" <maisha@...>
Date: Mon Sep 4, 2000 1:56 pm
Subject: Re: [PBML] Help with date format
maisha@...
Send Email Send Email
 
just curious everyone, but why use \d\d  instead of \d{2} - even just for
consistency sake?
is there a particular reason for using \d\d instead?

maisha

$data[0] =~ s<^(\d{4})[ /-]?(\d\d)[ /-]?(\d\d)$><$3$2$1>;

#754 From: "Maisha Walker" <maisha@...>
Date: Mon Sep 4, 2000 1:59 pm
Subject: Re: [PBML] Help with date format
maisha@...
Send Email Send Email
 
hey, isn't the problem with this though, that you cannot as simply account
for the addition of spaces, dashes or slashes to the date?  that was one of
the prerequisites of the person who had the question.

for example, what if your date looked like this:
2000-08-23

or if it sometimes looked like the above and sometimes looked like this:
20000823

the program below would not work anymore.

i'm a beginner, so let me know if i've missed something!

maisha
-----Original Message-----
From: Greg Webster <greg@...>
To: perl-beginner@egroups.com <perl-beginner@egroups.com>
Date: Sunday, September 03, 2000 10:26 PM
Subject: Re: [PBML] Help with date format




Personally...

To convert 20000803 (and be able to do cool things with the values
individually), I'd do something like the following:

$wholedate = '20000803';
@alldigits = split(//, $wholedate);
$year = join('', @alldigits[0..3]);
$month = join('', @alldigits[4..5]);
$day = join('', @alldigits[6..7]);

print "Year: $year : Month: $month : Day: $day\n";

Then you can easily deal with all of the dates in bits. There's really no
reason to complicate matters here.

BTW, I'm sure is Awk type formats and $1, $2, $3 etc...this could be
simplified
further.

Greg

--
< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
|   |  |  GREG WEBSTER - greg@...   |  |   |  |
<_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>

#755 From: "Oliver Manickum" <oliver@...>
Date: Mon Sep 4, 2000 2:13 pm
Subject: RE: [PBML] Help with date format
oliver@...
Send Email Send Email
 

Hey Maisha,

        I would try to compensate for both.. ie.        if a user sometimes used 2000-05-03 or sometimes used 20000503 then i would first do this

        $date = '2000/05/03';
        $date =~ s/\-\/\\//; # Accomodate for a - or a \ or a / or whateva else the user might separate the date by.....

       
        then u can play with it in the form of 20000505

- Olly
Oliver Manickum
____________________________
ePages Internet & Multimedia
http://www.epages.net/
Tel : +27 (0)31 2651281

-----Original Message-----
From: Maisha Walker [mailto:maisha@...]
Sent: Monday, September 04, 2000 4:00 PM
To: perl-beginner@egroups.com
Subject: Re: [PBML] Help with date format


-------------------------- eGroups Sponsor -------------------------~-~>
The Five Secrets Of A Successful Product Launch
FREE right now at:
http://click.egroups.com/1/8592/15/_/12898/_/968076180/
---------------------------------------------------------------------_->

hey, isn't the problem with this though, that you cannot as simply account
for the addition of spaces, dashes or slashes to the date?  that was one of
the prerequisites of the person who had the question.

for example, what if your date looked like this:
2000-08-23

or if it sometimes looked like the above and sometimes looked like this:
20000823

the program below would not work anymore.

i'm a beginner, so let me know if i've missed something!

maisha


#756 From: "Maisha Walker" <maisha@...>
Date: Mon Sep 4, 2000 2:17 pm
Subject: Re: [PBML] Help with date format
maisha@...
Send Email Send Email
 
oh yeah - that *is* simple!
 
Thank you!
maisha
-----Original Message-----
From: Oliver Manickum <oliver@...>
To: perl-beginner@egroups.com <perl-beginner@egroups.com>
Date: Monday, September 04, 2000 10:17 AM
Subject: RE: [PBML] Help with date format


Hey Maisha,

        I would try to compensate for both.. ie.        if a user sometimes used 2000-05-03 or sometimes used 20000503 then i would first do this

        $date = '2000/05/03';
        $date =~ s/\-\/\\//; # Accomodate for a - or a \ or a / or whateva else the user might separate the date by.....

       
        then u can play with it in the form of 20000505

- Olly
Oliver Manickum
____________________________
ePages Internet & Multimedia
http://www.epages.net/
Tel : +27 (0)31 2651281

-----Original Message-----
From: Maisha Walker [mailto:maisha@...]
Sent: Monday, September 04, 2000 4:00 PM
To: perl-beginner@egroups.com
Subject: Re: [PBML] Help with date format


-------------------------- eGroups Sponsor -------------------------~-~>
The Five Secrets Of A Successful Product Launch
FREE right now at:
http://click.egroups.com/1/8592/15/_/12898/_/968076180/
---------------------------------------------------------------------_->

hey, isn't the problem with this though, that you cannot as simply account
for the addition of spaces, dashes or slashes to the date?  that was one of
the prerequisites of the person who had the question.

for example, what if your date looked like this:
2000-08-23

or if it sometimes looked like the above and sometimes looked like this:
20000823

the program below would not work anymore.

i'm a beginner, so let me know if i've missed something!

maisha


#757 From: koetzler@...
Date: Mon Sep 4, 2000 2:44 pm
Subject: Net::POP3
koetzler@...
Send Email Send Email
 
I was using the Net::POP3 module for checking my emails but after
including the "Timeout -> 15" in

$pop = Net::POP3->new($mailserver, Timeout->15) or $errcode = 1;

my program doesn't works anymore with some pop servers. I always get
a 'timeout message', even if I remove the Timeout. My program don't
works like before. I'm accessing thru a proxy.

Anyone have noticed some problems with the Timeout option?


Marcos Koetzler
koetzler@...

#758 From: joach@...
Date: Mon Sep 4, 2000 3:30 pm
Subject: Re: [PBML] Help Reversing Data
joach@...
Send Email Send Email
 
Carlo this does work ..... I just ran it and it's fine.   Maybe a bad
cut and paste the first time...

Now I understand the /n   that's a new line   ........ but why the "
" about the Header.....???
Could you post us a small note as to how this works....and it works very
fine indeed.

Thanks again.....gives me another small utility that is useful

John

#!/usr/bin/perl -w
use strict;

my $infile  = shift;
my $outfile = shift;
my $header='"My Header"';
  print "Reversing date sequence\n";

  open (IN,$infile) || die "Could not open $infile $!";
  open (OUT, ">$outfile")|| die "can't open $outfile: $!";
  my @data = (<IN>);


  push @data,"$header\n";

  @data = reverse @data;

  print OUT @data;
  close IN;
  close OUT;





Carlo Antonio Tan wrote:

> try replacing the line:
>
>  push @data,$header;
>
> with:
>
>  push @data,"$header\n";
>
> hth,
> Carlo
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/

#759 From: Andrew Johnson <andrew-johnson@...>
Date: Mon Sep 4, 2000 5:10 pm
Subject: Re: [PBML] Help with date format
andrew-johnson@...
Send Email Send Email
 
! just curious everyone, but why use \d\d instead of \d{2} - even just
! for consistency sake? is there a particular reason for using \d\d
! instead?

To be honest, here is why I did it that way:

     \d{4} is shorter than \d\d\d\d
     \d\d  is shorter than \d{2}

:-)

andrew

--
Andrew L. Johnson   http://members.home.net/andrew-johnson/
       The generation of random numbers is too
       important to be left to chance.

#760 From: Greg Webster <greg@...>
Date: Mon Sep 4, 2000 7:08 pm
Subject: Re: [PBML] Help with date format
greg@...
Send Email Send Email
 
Sorry, you're right...but this is easily accomplished with one line.

$wholedate = '20000803';
$wholedate =~ s/[\/-\\\.//g;     #removes / - \ and . Add as needed
@alldigits = split(//, $wholedate);
$year = join('', @alldigits[0..3]);
$month = join('', @alldigits[4..5]);
$day = join('', @alldigits[6..7]);

print "Year: $year : Month: $month : Day: $day\n";

Greg

On Mon, 04 Sep 2000, you wrote:
>
> hey, isn't the problem with this though, that you cannot as simply account
> for the addition of spaces, dashes or slashes to the date?  that was one of
> the prerequisites of the person who had the question.
>
> for example, what if your date looked like this:
> 2000-08-23
>
> or if it sometimes looked like the above and sometimes looked like this:
> 20000823
>
> the program below would not work anymore.
>
> i'm a beginner, so let me know if i've missed something!
>
> maisha
> -----Original Message-----
> From: Greg Webster <greg@...>
> To: perl-beginner@egroups.com <perl-beginner@egroups.com>
> Date: Sunday, September 03, 2000 10:26 PM
> Subject: Re: [PBML] Help with date format
>
>
>
>
> Personally...
>
> To convert 20000803 (and be able to do cool things with the values
> individually), I'd do something like the following:
>
> $wholedate = '20000803';
> @alldigits = split(//, $wholedate);
> $year = join('', @alldigits[0..3]);
> $month = join('', @alldigits[4..5]);
> $day = join('', @alldigits[6..7]);
>
> print "Year: $year : Month: $month : Day: $day\n";
>
> Then you can easily deal with all of the dates in bits. There's really no
> reason to complicate matters here.
>
> BTW, I'm sure is Awk type formats and $1, $2, $3 etc...this could be
> simplified
> further.
>
> Greg
>
> --
> < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
> |   |  |  GREG WEBSTER - greg@...   |  |   |  |
> <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>
--
< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
  |   |  |  GREG WEBSTER - greg@...   |  |   |  |
<_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>

#761 From: Andrew Johnson <andrew-johnson@...>
Date: Mon Sep 4, 2000 7:54 pm
Subject: Re: [PBML] Help with date format
andrew-johnson@...
Send Email Send Email
 
! Sorry, you're right...but this is easily accomplished with one line.
!
! $wholedate = '20000803';
! $wholedate =~ s/[\/-\\\.//g;     #removes / - \ and . Add as needed

Ouch! Greg, besides forgetting the closing ] on the character class,
you do realize that your regex will remove a whole lot more than you
think it does (removing all upper case letters and all digits, and
several punctuation characters -- and it won't remove the '-'
character).

I think you meant: [\/\\\.-] , placement of the '-' is crucial inside
of character classes.

regards,
andrew

--
Andrew L. Johnson   http://members.home.net/andrew-johnson/
       I drink to make other people interesting.
           -- George Jean Nathan

#762 From: Greg Webster <greg@...>
Date: Mon Sep 4, 2000 8:49 pm
Subject: Re: [PBML] Help with date format
greg@...
Send Email Send Email
 
Heh, I really should test what I write. Forgive me, it's been a hell of a week.
You are absolutely right about the placement and order.

Greg

On Mon, 04 Sep 2000, you wrote:
> Ouch! Greg, besides forgetting the closing ] on the character class,
> you do realize that your regex will remove a whole lot more than you
> think it does (removing all upper case letters and all digits, and
> several punctuation characters -- and it won't remove the '-'
> character).
>
> I think you meant: [\/\\\.-] , placement of the '-' is crucial inside
> of character classes.
>
> regards,
> andrew
>
> --
> Andrew L. Johnson   http://members.home.net/andrew-johnson/
>       I drink to make other people interesting.
>           -- George Jean Nathan
--
< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
  |   |  |  GREG WEBSTER - greg@...   |  |   |  |
<_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>

#763 From: "Maisha Walker" <maisha@...>
Date: Mon Sep 4, 2000 10:35 pm
Subject: Re: [PBML] Help with date format
maisha@...
Send Email Send Email
 
ha ha ha - that's great!

maisha
-----Original Message-----
From: Andrew Johnson <andrew-johnson@...>

! just curious everyone, but why use \d\d instead of \d{2} - even just
! for consistency sake? is there a particular reason for using \d\d
! instead?

To be honest, here is why I did it that way:

     \d{4} is shorter than \d\d\d\d
     \d\d  is shorter than \d{2}

:-)

andrew

#764 From: joach@...
Date: Tue Sep 5, 2000 12:23 am
Subject: Changing values field values *100
joach@...
Send Email Send Email
 
I have one more request.... then I have to settle down to catch up on my
reading in Perl.

I have a file that reads as 20000903,1.25,2.25.1.75,2.25,21540
all of the values in fields 1,2,3,4 have to be multilpied by 100 or if
you wish the decimal moves to the right two places....... the date does
not change nor does field 5.........

This is another thing I can't seem to find in books.....


Tia

John



my $infile  = shift;
my $outfile = shift;

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

     while (<IN>) {
         chomp;
        #code goes here......

     }

     close (IN);
     close (OUT);

__END__

Messages 735 - 764 of 27470   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help