Thanks Wags for your reply , I should have seen the
logical loop problem my fault :)
The second one did work also , Thanks again
--- [EMAIL PROTECTED] wrote:
> First question is that you are repeatedly printing
> the data by concatenating the data read into $data
> and printing $data over and over. Try this:
>
> while(<>){
> $data .= $_;
> print $_;
> }
>
> This will place all the text read into $data ( .=
> is concatenate what read into $data).
> The print just prints what has been read in( you
> could just say print ; and it would default to $_,
> but I like to see what I am printing).
>
> Second one I am unsure what you really want. Are
> these words, so besides xyz and xy, axyc would be
> found also. Are you breaking on the whitespace? If
> so, then this could be a start:
>
> #!perl -w
>
> while ( <DATA> ) {
> chomp;
> if ( /\b([a-z0-9]*xy[a-z0-9]*)/i ) { # on a word
> boundary, if xy has anything before or after
> # it which is alpha or a number (
>you
> could add others to
> # the character class or take
>away) and
> ignore case
> my $MyHit = $1;
> printf "%-s\n", $MyHit;
> }
> }
> __DATA__
> abc xyz
> def ghj
> vbn xy
>
> Output is:
>
> xyz
> xy
>
>
> Wags ;)
> -----Original Message-----
> From: Pankaj Agarwal [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 12, 2002 14:21
> To: [EMAIL PROTECTED]
> Subject: 2 Beginner questions, please help
>
>
> Hi All,
>
> I am just starting on it and kind of overwhelmed
> with
> the amazing capabilities of perl, how ever for now
> I
>
> have 2 questions :
>
> Q1) while(<>){
> $data=$data . $_;
> print $data;
> print "loop\n"
> }
>
> and calling it like this c:\>perl simple.pl
> data.txt
> it should print all the lines of data.txt once but
> it
> doesn't but it print all the lines 2-3 times before
> next ?
>
> Q2)i want to write a foreach sort of loop such that
> for each pattern matched, it should return me the
> exact data matched for ex. :
>
> $data contains :
> abc xyz
> def ghj
> vbn xy
>
> and pattern is /xy/
>
> then loop shud be such that at each repetition
> some local variable should be set to each matched
> word
> like in this case in first pass $local should be
> set
> to "xyz" then in next pass "xy"
>
> Thanks for ur time.
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe:
> http://listserv.ActiveState.com/mailman/mysubs
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe:
http://listserv.ActiveState.com/mailman/mysubs
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs