----- Original Message ----- 
From: "Harry Putnam" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 16, 2003 11:47 PM
Subject: Capture a printing function into an array


>
> My script has a function that I want to just print its output in some
> circumstances but in others I need to capture its output into an
> array for further processing:
>
>   sub strip_to_bone {
>    if(/[Ss]ource/ && /[Dd]estination/){
>       ($line = $line) =~ s/[Ss]ource/Src/g;
I am a newbie as well but this line makes no sence to me why do you have
($line = $line) ???
>       ($line  = $line)  =~ s/[Dd]estination/Dst/g;

same for this line

>  $line  =~ s/(^[^ ]+, )([0-9][^ ]+ [0-9][^ ]+)(.*)(Src[^ ]+
[0-9]+)(.*)(Dst[^ ]+ [0-9]+)/$2 $4 $6/;
>       $line = '';
>       printf " %s %s %-28s %s\n", "<$.>", "$2", "$4", "$6";

Here you dont need to quote your variables
printf " %s %s %-28s %s\n", <$.>, $2, $4, $6;

BTW why are you doing <$.> ??

>   }
> }
>
> I've tried various renditions of sprintf and eval but my syntax is
> still allowing the function to print to standard out.
>
> What is the correct way to do this so that the functions' output goes into
> an array (simplified below):
>
>  if ($opt_l){
>       @c = sprintf(my_func());
sprintf will return a scalar, if you want an array you need to split
 @c = split "",sprintf(my_func());

> #      @c = eval my_func();
>        for (@c){
>          print "Got it =>  $_\n";
>        }
>     }
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

hTh,
Mark G



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to