Solved

How to cut a long line Perl?

Posted on 2011-09-27
5
224 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 500 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 84

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now