Solved

How to cut a long line Perl?

Posted on 2011-09-27
5
225 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

19 Experts available now in Live!

Get 1:1 Help Now