Perl - How do you break the long line of codes into 2?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - How do you break the long line of codes into 2?
# 1  
Old 03-06-2009
Perl - How do you break the long line of codes into 2?

I'm trying to make this long line of codes in Perl looks nice by dividing it into 2 lines...

Before:
`echo "blahblahblahblahblahblahblahblahblahblahblah" > ~/lalala/lalala/lalala/lalala/lalala/abc`;

After:
`echo "blahblahblahblahblahblahblahblahblahblahblah" >
~/lalala/lalala/lalala/lalala/lalala/abc`;

But the command stops working if I do that. Is there any way to break it into 2 lines like what I have (in After) and still ensure that it works?

Last edited by teiji; 03-06-2009 at 01:28 AM.. Reason: fixed command
# 2  
Old 03-06-2009
perl doesn't have an echo function/command.
# 3  
Old 03-06-2009
Quote:
Originally Posted by KevinADC
perl doesn't have an echo function/command.
Oh sorry, the command should be in ` ` (backdash) because I'm using the Unix command inside of Perl.

Edited the topic.
# 4  
Old 03-06-2009
just break it into two lines then:

`echo "whatever"`;
`echo "whatever\n"`;

Its really pretty silly though to use perl to just run shell commands.
# 5  
Old 03-06-2009
He's using the shell because it's a tad easier to redirect to a new file than to setup Perl's filedescriptor. Still, I wouldn't use backtick operators here, because there's no output from the command to be captured and used by perl.

Instead, I would do this:
Code:
$cmd=q(echo "whatever") . 
q(> somefile.txt);
system $cmd;
# OR
`$cmd`

# 6  
Old 03-06-2009
I guess if you had to write the same code over and over many many times it is easier, but taking the time to write the code in perl (assuming one knows how) might take all of one minute. To each his own though. TIMTO(bad)WTDI. Smilie

Good point about using system() instead of tiks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break one long string into multiple fixed length lines

This is actually a KSH under Unix System Services (Z/OS), but hoping I can get a standard AIX/KSH solution to work... I have a very large, single line file in Windows, that we download via FTP, with the "SITE WRAP" option, into a Z/OS file with an LRECL of 200. This essentially breaks the single... (4 Replies)
Discussion started by: bubbawuzhere
4 Replies

2. Shell Programming and Scripting

How to break the line to the one above?

Hello everyone! I'm trying to make the below file1 look like file2, can anyone help? Basically I just hit backspace on every line that starts with a number. Thanks! file1: THIS#IS-IT1 4 THIS#IS-IT2 3 THIS#IS-IT3 2 THIS#IS-IT4 1 Result > file2: (4 Replies)
Discussion started by: demmel
4 Replies

3. UNIX for Dummies Questions & Answers

VI Line Break?

So I'm in a Unix class and our assignment was to go into VI and write a script to make this file tree. At the end of it, I'd like it to echo "This is the file tree you've created" then a line break, then . But I'm not sure as to who to do it. Is there a way for when I run it (./filesystem), the... (4 Replies)
Discussion started by: bbowers
4 Replies

4. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

5. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

6. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. Shell Programming and Scripting

Perl break a file

I am trying to break a large file into smaller ones, with the break defined by the character "*". The following is the code I have so far which breaks the input file on every line instead of at the "*" character. Input file: 1 2 3 4 *5 6 7 8 9 Code: #!/usr/bin/perl... (2 Replies)
Discussion started by: cold_Que
2 Replies

8. Shell Programming and Scripting

bash awk codes to perl

Hi, I am interesting in writing the following bash codes into perl My script is simple take field 2 in /etc/passwd and put into an array #!/bin/bash PASSWD_FILE=/etc/passwd A=(`awk -F: ' { print $2 }' $PASSWD_FILE `) Can someone give me equivalent codes in perl ? (1 Reply)
Discussion started by: phamp008
1 Replies

9. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies

10. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies
Login or Register to Ask a Question