hi all,
i am working to split the data in my array as follows but ended up clueless,
hoope some of u can help.
@text # contains values of a phone directory
$text[0] contains john=012345678
$phone1 = ?
let say i wanted to grab just the values'012345678'.
how should i go on truncating the value
It seems that when i am working with network programming, the input from the
client will contain carrier return characters which the server interpreted
as 2 carrier-return, how do i truncate the end carrier return characters?
kindly advice... ...
thanks!
Hey Chaoz,
#!/usr/bin/perl
use strict;
open(FILE,');
close(FILE);
for(@text) {
/(d+)$/; # Match only the numbers at the end of the string
# and store them in '$1' to be printed out on the
# next line followed by a new line character
print $1,"\n";
}
exit;
shawn
-
>
> for(@text) {
> /(d+)$/; # Match only the numbers at the end of the string
^^
this should actually be (\d+)
I would actually conditionally print also, like so:
print $1 if /(\d+)$/;
And depending on the size of the file, instead of reading the whole
thing into memory wi
ChaoZ InferNo wrote:
> @text # contains values of a phone directory
> $text[0] contains john=012345678
>
> $phone1 = ?
>
> let say i wanted to grab just the values'012345678'.
if the format of $text[0] is always name=number you can use split
instead of a regex.
perldoc -f split
--
To uns
Actually, the content of the file looks something like:-
name=john
id=12345
password=12345
colour=blue
I am trying to grab the value field of each line and assigned it to be a
variable.
I tried the regular expressions, but seems like the syntax is wrong or
something,
@file = ; #small file anywa
Regular expressions are overkill for what you're trying to do. It seems like
using 'split' should do exactly what you need.
#!/usr/bin/perl -W
use strict;
open(IN,";
close(IN);
for(@list) {
chomp;
my($field,$value) = split(/=/,$_); # split each line on '='
print "Your $field is $value. \n";
Ok, first, thanks for the correction and input David... I agree 100% with what you
say.
Secondly, am I just crazy, or doesn't split USE regex? Since this is the second
mention the regex is overkill, and that split will work, I am a bit confused... When
you can say $var=split(/=|:/); it tell
Curious, but I've always thought that regex was much quicker then
split for situations such as this...
I'd always figured that split was basically a (and the regex for this
is probably wrong, but you can get the jist of it) /[^($delimiter |
end of string)/ with a dumping of the match minus the
> Actually, the content of the file looks something like:-
> name=john
> id=12345
> password=12345
> colour=blue
Ok, how about this then...
This is based on the fact that name, id, password, colour appear for every record
whether they have a value or not, and that none of the values after the '
...it certainly looks like a regex to me
-Original Message-
From: Shawn [mailto:[EMAIL PROTECTED]]
Sent: 17 May 2002 16:03
To: Scot Robnett; ChaoZ Inferno; [EMAIL PROTECTED]
Subject: Re: regular expression
Ok, first, thanks for the correction and input David... I agree 100% with
what y
I don't believe that a regex would be faster in an instance like this, but
someone please correct me if I'm wrong. It seems that it would add (albeit a
very minimal amount) processing overhead to apply a regular expression to
each line rather than using the built-in split function on it, depending
I just happened to write exactly this the other day,
as a generic configuration file reader. Here's the
basics:
sub readINI {# argument: filename
my %params;
open( INIFILE, $_[0] )
|| die "Could not open $_[0]\n";
while() {
if(! /^#/ ) { # Allow comments
chomp;
Anybody else having trouble reaching search.cpan.org or wait.cpan.org today?
I can get to the main site, but I can't get to module documentation.
Scot R.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197
On Fri, 10 May 2002, fliptop wrote:
> Lance Prais wrote:
> > If I am going to sendmail from an Internet using CGI does anyone know all
> > the modules I will need to install? This may answer all my questions.
>
> i use mime::lite and it works great and is simple to use.
Ditto.
--
Eric P.
Los
15 matches
Mail list logo