Stick Lines and Dividers Between Text

V

vjp2

is that x or *???

perl -pe 'if ($.%4==2){$_.="-" x 37} elseif {$.%4==0) {$_.="=" x 37} $_.="\n"'
< %1 >%1
 
J

John Bokma

is that x or *???

perl -pe 'if ($.%4==2){$_.="-" x 37} elseif {$.%4==0) {$_.="=" x 37}
$_.="\n"' < %1 >%1

x

"-" x 37 is an expression that results in

----------------- ... ---
<-- 37 characters -->
 
J

Joe Smith

is that x or *???
{$_.="-" x 37}

Did you try testing it?

C:\>perl -le "print 12 * 4; print 12 x 4"
48
12121212

Clearly x is appropriate for strings like "-" and "=".
-Joe
 
V

vjp2.at

What is
$_.=
? Concatenate what follows to a new line immediately after the current?
Is it possible the equal sign is redundant?

Many thanks. I made a bit of progress. At least it doesn't bomb!

Using DOS GNU v4. I had to use " " to enclose the expression.
And change the internal "" to `` not ''.
But I'm getting a no-op. Is it possible it resets $. for every line?


- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
V

vjp2.at

First thanks for all the help and for putting up with me.

Here's how I think this is supposed to work:
If the line number mod 4 is two, add a spacer of hyphens,
Every fourth line should be spaced by equal signs
the thing should be double spaced.
(I am using fold, but it would be cool if perl did justification)

I tried moving it to my Unix Shell ISP. Here's what I got

Both DOS and Bash do this "command not found".
I don't understand, does perl try to act like a bat/cmd/sh file?

perl -pe "if ($.%4==2) {$_.='\n'.`-` x 37} elsif ($.%4==0) {$_.='\n'.`=` x 37} else {$_.=`\n`}" junk.tmp

-bash: : command not found
-bash: -: command not found
-bash: =: command not found
-bash: n: command not found
syntax error at -e line 1, near "{.="
Number found where operator expected at -e line 1, near "x 37"
(Do you need to predeclare x?)
Number found where operator expected at -e line 1, near "x 37"
(Do you need to predeclare x?)
Execution of -e aborted due to compilation errors.
-bash: : command not found
-bash: : command not found
-bash: : command not found
bash-3.00$


- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
A

anno4000

First thanks for all the help and for putting up with me.

Here's how I think this is supposed to work:
If the line number mod 4 is two, add a spacer of hyphens,
Every fourth line should be spaced by equal signs
the thing should be double spaced.
(I am using fold, but it would be cool if perl did justification)

I tried moving it to my Unix Shell ISP. Here's what I got

Both DOS and Bash do this "command not found".
I don't understand, does perl try to act like a bat/cmd/sh file?

perl -pe "if ($.%4==2) {$_.='\n'.`-` x 37} elsif ($.%4==0) {$_.='\n'.`=`
x 37} else {$_.=`\n`}" junk.tmp

-bash: : command not found
-bash: -: command not found

[etc.]

Sure. You're have messed up your quotes royally, at least for a Unix
shell.

The outer quotes around the Perl program should be single quotes.
The inner quotes should all be double quotes. The backticks are
entirely wrong.

Anno
 
V

vjp2.at

Many thanks. Did that. Only message I get now is three "command not found"





- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
A

anno4000

Many thanks. Did that. Only message I get now is three "command not found"

Did what? Please quote some context with your reply. Not everyone
has the article you're replying to in view.

Either you don't have a Unix shell or you didn't do what I told you.
What is the exact text of your perl call now?

Anno
 
J

Joe Smith

What is
$_.=
? Concatenate what follows to a new line immediately after the current?

You mean you don't know what
$_ = "foo";
$_ .= "bar";
print $_;
does? If so, you really really need to read and understand 'perldoc perlop'.
Is it possible the equal sign is redundant?

Absolutely not.
Many thanks. I made a bit of progress. At least it doesn't bomb!

Using DOS GNU v4. I had to use " " to enclose the expression.

MS-DOS and Unix have different quoting conventions.
Don't try to use the same command line format for both, it does not work.

I run cygwin (www.cygwin.com) on my Windows XP machine so that I
can use bash there, the same as Unix.
And change the internal "" to `` not ''.

Don't try that with bash. Changing "" to `` WILL NOT WORK!

bash% perl -e 'print `date` x 3;'
But I'm getting a no-op. Is it possible it resets $. for every line?

No, you have got some other misunderstanding.

I notice that you have not posted
a) the actual code you're trying to run on DOS, and
b) the actual code you're trying to run with bash on Unix.

The other message you posted (Wed, 7 Feb 2007 13:23:38 +0000 (UTC))
is particularly lacking in details.

-Joe
 
J

Joe Smith

Michele said:
For "internal" strings you can use alternate delimiters.

Don't forget to mention alternate quoting syntax: q() and qq().

$_ .= qq(\n) . q(-) x 37;
 
V

vjp2.at

(0) Ok, back up to the beginning (thanks,sorry).

tried perl -pe 'print "goat \n"' on Unix and perl -pe "print 'goat \n'" on DOS

both cases it stood there waiting for further input

I hit ^D in Unix and ^Z in DOS and it just went to the shell prompt.

(1) This is what I ran on Unix

perl -pe 'if ($.%4==2) {$_ .= qq(\n).q(-) x 37} elsif ($.%4==0) {$_ .= qq(\n).q(=) x 37} else {$_ .= qq(\n)}' junk.tmp

and what I got was "command not found" three times.

(It seem like it is sending output to the shell as commands?)

(2) I was familiar with += form other languages but when I saw $_.= I thought
$_. and = , not $_ and .=

(3) Eventually I want to reformat the paragraphs to 37 characters wide
(looking for code to borrow) so I will probably not keep this as a one-liner.

- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
V

vjp2.at

# - This worked as a perl program just fine
# I still have no idea why the command line didn't
# - what are the relevant perl/bin top line commands?
# I took something from a sample and it didn't like it
# - I want to make this a "routine" with the 37 being a parameter.
# - is wrap a standard function in perl? v4 and v5?
# Would I be able to wrap the whole file at 37 cols
# then insert the separators.

while (<>) {
if ($.%4==2) {$_ .= qq(\n).(q(-) x 37).qq(\n)}
elsif ($.%4==0) {$_ .= qq(\n).(q(=) x 37).qq(\n)}
else {$_ .= qq(\n)}
print;
} continue { close ARGV if eof }

- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
I

Ian Wilson

(0) Ok, back up to the beginning (thanks,sorry).

tried perl -pe 'print "goat \n"' on Unix and perl -pe "print 'goat \n'" on DOS

The -p option makes perl read from STDIN if no filenames are specified.
Read perldoc perlrun

In the second example (DOS) remember that single quotes don't
interpolate variables and don't substitute meta characters like \n.

both cases it stood there waiting for further input

Because you used the -p option and didn't supply a filename?

This is what I ran on Unix

perl -pe 'if ($.%4==2) {$_ .= qq(\n).q(-) x 37} elsif ($.%4==0) {$_ .= qq(\n).q(=) x 37} else {$_ .= qq(\n)}' junk.tmp

and what I got was "command not found" three times.

I didn't.

$ perl -pe 'if ($.%4==2) {$_ .= qq(\n).q(-) x 37} elsif ($.%4==0) {$_ .=
qq(\n).q(=) x 37} else {$_ .= qq(\n)}' junk.tmp
aaa

bbb

-------------------------------------ccc

ddd

=====================================eee

fff

-------------------------------------ggg

hhh

=====================================iii
 
V

vjp2.at

Many thanks, still a mystery. But i got it to run it from a file.


- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
V

vjp2.at

In <[email protected]> by Ian Wilson <[email protected]> on Thu, 08 Feb 2007 14:11:04 +0000 we perused:


*+-Because you used the -p option and didn't supply a filename?

Wait! How many filenames? In & out or only in?
What if out should be the terminal?


- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
V

vjp2.at

*+-Huh?!? Are you referring to the shebang line? That is usually

*+- #!/usr/bin/perl

Yeah, thanks.. the one I copied had switches on it, I guess

- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
J

Joe Smith

In <[email protected]> by Ian Wilson <[email protected]> on Thu, 08 Feb 2007 14:11:04 +0000 we perused:
*+-Because you used the -p option and didn't supply a filename?

Wait! How many filenames? In & out or only in?

You can discover the answer to that question yourself by reading the docs.
As many as you want (zero names = read from STDIN).
In only.
What if out should be the terminal?

The -p option does not change where STDOUT goes.
 
T

Tad McClellan

Michele Dondi said:
: perl -pe 'if ($.%4==2){$_.="-" x 37} elseif {$.%4==0) {$_.="=" x 37} $_.="\n"'
^
^

Apart that the underlined curly above should
really be a paren, and that "elseif" should be spelled "elsif".


All of that was pointed out to this poster 4 months ago when he
posted this exact same code...

Message-Id: <[email protected]>
 
V

vjp2.at

BTW, my main problem was DOS-UNIX cr/lf.. stay tuned


- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top