Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to cut a long line Perl?

Posted on 2011-09-27
5
Medium Priority
?
252 Views
Last Modified: 2012-05-12
Hi,
In Perl I have the following long line. How can I make it 3 or 4 lines?

my @javaCmd = ('java', '-jar', "$mydir/dir/Tool-1.0.jar", $a1, @a2, $a3, $a4, $a5, $a6, $a7, $a8, @Fa9, $a10, @a11, $a12, $a13, $a14);

print "Running: @javaCmd\n";
system( @javaCmd ); 

Open in new window


Thanks,
0
Comment
Question by:Tolgar
  • 2
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
nemws1 earned 2000 total points
ID: 36713572
I usually split lines by commas, but really any newlines are considered the same as "whitespace" (tabs or spaces), so anywhere you have a space is a place where you can break your code onto a new line.
my @javaCmd = ('java', '-jar', "$mydir/dir/Tool-1.0.jar",
    $a1, @a2, $a3, $a4, $a5, $a6, $a7, $a8,
    @Fa9, $a10, @a11, $a12, $a13, $a14);

Open in new window

0
 
LVL 10

Expert Comment

by:jeromee
ID: 36713584
something like this?

print "Running: @javaCmd[0..4]\n@javaCmd[5..9]\n@javaCmd[10..14]\n@javaCmd[15..-1]";

Also, the fact that you are using $a1, $a2,... tells me that you might be better off using arrays, no?

0
 
LVL 23

Expert Comment

by:nemws1
ID: 36713594
If more of what jeromee is talking is about is what you're after (more lines in your output, not your code), then a simple solution would be:
print "Running: ", join("\n", @javaCmd), "\n";

Open in new window

Which will print each value of @javaCmd on a seperate line.
0
 
LVL 85

Expert Comment

by:ozo
ID: 36715578
I don't think that @javaCmd[15..-1] does what jeromee seems to think it does.
I agree with jeromee comment about $a1, $a2,... suggesting that you might be better off using arrays.
0
 
LVL 10

Expert Comment

by:jeromee
ID: 36717129
As usual, ozo is right.
the '-1' in your statement s/b replaced with a '$#javaCmd'
    print "Running: @javaCmd[0..4]\n@javaCmd[5..9]\n@javaCmd[10..14]\n@javaCmd[15..$#javaCmd]";

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question