justino berrun wrote:
> #hello, is there a way to split a string between a digit and character
> $string='hello...4546perl...2366Pogrammers..3435'; #e.g. would make three new
>strings
Try:
(my $ElementString = $string) =~ s /(\d+)(\D+)/$1-$2/g;
print "$ElementString\n";
$ElementString is th
Rob Dixon wrote:
>
> Justino Berrun wrote:
> > #hello, is there a way to split a string between a digit and character
> > #without losing the digit or the character
> > #Any help would be very appreciated
> >
> > $string='hello...4546perl...2366Pogrammers..3435'; #e.g. would
> > make three new
Justino Berrun wrote:
> #hello, is there a way to split a string between a digit and character
> #without losing the digit or the character
> #Any help would be very appreciated
>
> $string='hello...4546perl...2366Pogrammers..3435'; #e.g. would
> make three new strings
>
> @newstrings=split(/(\
justino berrun wrote:
> #hello, is there a way to split a string between a digit and character
> #without losing the digit or the character
> #Any help would be very appreciated
>
> $string='hello...4546perl...2366Pogrammers..3435'; #e.g. would
> make three new strings
>
> @newstrings=split(
On Wed, 22 Jan 2003 02:46:27 +0800, Justino Berrun wrote:
> #hello, is there a way to split a string between a digit and character
> #without losing the digit or the character
> #Any help would be very appreciated
>
> $string='hello...4546perl...2366Pogrammers..3435'; #e.g. would make three
on a side note, if you CAN use perls internal char classes you really want to do
that
firstly to avoid typos, secondly, they're much faster.
and if you're using the same regexp over and over again, you *might* want to
concider building it outside the loop with the /o switch
(this all performace b
On Tue, 3 Jul 2001, Luke Bakken wrote:
> > > > Unpack works well with fixed format data like this.
> > >
> > > Why would you use unpack when this can be easily split apart with a regex?
> > > I'd think unpack would be overkill!
>
> why is it overkill any more that a regex?
Are you saying we shou
$year) = $dateis =~ /([0-9]+)([A-Za-z]+)([0-9]+)/;
>
> It makes me sleeper at night
>
>
> - Original Message -
> From: "John Edwards" <[EMAIL PROTECTED]>
> To: "'Will Crain'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
>
---
From: "John Edwards" <[EMAIL PROTECTED]>
To: "'Will Crain'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 3:54 PM
Subject: RE: A Split Question
> Sorry to pick holes in your first post to the list ;) but this part of
y
01 15:41
To: [EMAIL PROTECTED]
Subject: RE: A Split Question
-- Original Message --
>My file has dates in it that either come out as "2Jul2001" or "21Jul2001".
> So one or two digits for the day, three for the month, and four for the
>year.
>
>So I would like t
-- Original Message --
>My file has dates in it that either come out as "2Jul2001" or "21Jul2001".
> So one or two digits for the day, three for the month, and four for the
>year.
>
>So I would like to split out the day, month, year, and am interested in
>splitting techniques, where there are n
> > Unpack works well with fixed format data like this.
>
> Why would you use unpack when this can be easily split apart with a regex?
> I'd think unpack would be overkill!
>
> -- Brett
if you had thousands of dates to split up, unpack is much faster than
regexes. way way faster.
Luke
On Tue, 3 Jul 2001, Luke Bakken wrote:
> my @dates = qw(2Jul2001 21Jul2001);
>
> for my $date (@dates)
> {
> my ($month, $day, $year) =
> length $date == 8 ?
> unpack 'AA3A4', $date :
> unpack 'A2A3A4', $date;
>
>
my @dates = qw(2Jul2001 21Jul2001);
for my $date (@dates)
{
my ($month, $day, $year) =
length $date == 8 ?
unpack 'AA3A4', $date :
unpack 'A2A3A4', $date;
print "M: ", $month, "\tD: ", $day, "\tY: ",
Aah... I was so close. But slightly on the wrong track by using "split".. I had the
regex as below.
Now I just need to work out how to use this with my sort hash question.
Thanks Pierre.
In reply-to "Pierre Smolarek" <[EMAIL PROTECTED]> on Tue Jul 3 13:01:43 2001
>my $dateis = "2Jul2001"
You do have delimiters there (of a sort)
2Jul2001
^^ ^
Number Letter Number
@dates = qw(2Jul2001 21Jul2001);
foreach (@dates) {
/(\d+)(\D+)(\d+)/;
$day = $1;
$month = $2;
$year = $3;
print "Day $day, month $month, year $year\n";
}
John
my $dateis = "2Jul2001";
my ($date,$month,$year) = $dateis =~ /([0-9]+)([A-Za-z]+)([0-9]+)/;
print "$date - $month - $year \n";
:)
with regards,
Pierre
- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 12:24 PM
Subject: A Split Questio
17 matches
Mail list logo