
reading char by char in a string
Quote:
>How can I read special parts from a string? say:
>i have string that contains: someinfo_moreinfo_evenmoreinfo_
That is not the same question that you put in your Subject header.
Please be a bit more precise in wording your questions.
I don't know which one to answer...
reading char by char in a string
perldoc -f sysread
(but nobody really wants to do this, it will be slow)
_processing_ char by char in a string
foreach ( split //, $string ) {
# do something with char in $_
}
Quote:
>I would like to store the info between the underscores ("_").
So there should be two "matches"
moreinfo
evenmoreinfo
since someinfo is NOT between underscores?
Quote:
>But I'm
>still new at this and need help....
Though split(), as pointed out in another followup, will do the
job with the particular problem you presented, you can do it
with a regex too.
perldoc perlre
perldoc perlop
-----------------------------
#!/usr/bin/perl -w
use strict;
$_ = 'someinfo_moreinfo_evenmoreinfo_';
#while ( /_([^_]*)(?=_)/g ) { # same thing, all on one line
while ( /_ # underscore
( # start remembering matched chars in $1
[^_]* # zero or more of anything except underscore
) # stop remembering matched chars
(?=_) # see if the next char is underscore, without
# counting it in this match (because we
# need it at the beginning of the _next_ match)
/gx ) {
print "$1\n"; # do something with the matched chars in $1
Quote:
}
-----------------------------
--
Tad McClellan SGML Consulting
Fort Worth, Texas