Solved

How to cut a long line Perl?

Posted on 2011-09-27
5
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

615 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