Stuck on perl printing same lines. - Overclock.net - An Overclocking Community

Forum Jump: 

Stuck on perl printing same lines.

 
Thread Tools
post #1 of 3 (permalink) Old 07-07-2016, 03:39 PM - Thread Starter
Linux > All
 
Tadaen Sylvermane's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ
Posts: 1,627
Rep: 60 (Unique: 55)
Code:
while (my $line = <INPUT>) {
        if ($line =~ /$source/) {
                my @source = split / /, $line;
                my $endvalue1 = $source[4];
  #            print OUTPUT $endvalue1;
        }
        elsif ($line =~ /$target/) { 
                my @target = split / /, $line;
                my $endvalue2 =  $target[1];
#              print OUTPUT $endvalue2;
        } 
        elsif ($line =~ /$reason/) {
                my $endvalue3 = $line;
 #             print OUTPUT $endvalue3;
        }
}

This is in perl. Just posting relevant section, is a small script. How can I take $endvalue[123] and print them out on the same line.

Basically this...

print OUTPUT "$endvalue1 $endvalue2 $endvalue3";

That or how can I make those local variables into global ones.

yessir.gif[Free Your Mind!]yessir.gif
devil.gif
echo"The`uname`Club"devil.gif

"Figure out everything you want in life right now, then plan on spending the next 25 years getting it piece by piece..."


Think Different. List of Linux System Builders / Retailers
Tadaen Sylvermane is offline  
Sponsored Links
Advertisement
 
post #2 of 3 (permalink) Old 07-07-2016, 07:31 PM
New001
 
Join Date: Feb 2016
Posts: 2,668
Can you turn that part of the script into a subroutine, return an array and call it from elsewhere?
something like:
Code:
sub controller {
    my $values = getValues();
    $stringify = join(" ", @values);
    print OUTPUT $stringify;
}


sub getValues {
    while (my $line = <INPUT>) {
        #....
    }
    @values = ($endvalue1, $endvalue2, $endvalue3);
    return @values;
}
spinFX is offline  
post #3 of 3 (permalink) Old 07-08-2016, 08:17 AM - Thread Starter
Linux > All
 
Tadaen Sylvermane's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ
Posts: 1,627
Rep: 60 (Unique: 55)
Is a good idea. I should have marked it solved. Got what I was looking for by writing to a variable then printing the variable as such.
Code:
my $buffer = "";

open my $writeout, ">>", \$buffer;

...

print STDOUT "$buffer\n";

yessir.gif[Free Your Mind!]yessir.gif
devil.gif
echo"The`uname`Club"devil.gif

"Figure out everything you want in life right now, then plan on spending the next 25 years getting it piece by piece..."


Think Different. List of Linux System Builders / Retailers
Tadaen Sylvermane is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off