Solved

How to cut a long line Perl?

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

749 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