Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Odd string wrap

Reply
Thread Tools

Odd string wrap

 
 
gbostock@excite.com
Guest
Posts: n/a
 
      08-05-2005
I'm trying to write a script that will do (UNIX) diffs on a set of
files. I also want to pipe the results to grep -v to eliminate the
trivial differences. The command gets quite long because of that and
also because I use the full path name for the files. So the command
looks like this:
`diff /dir/dir1/dir2/dir3/file1 /dir/dir1/dir2/dir3/file2 | grep -v
somestring | grep -v someotherstring ... >
/dir/dir1/dir2/dir4/file.diff`

Somehow that string is wrapped so that the UNIX command processor sees:

diff /dir/dir1/dir2/dir3/file1
/dir/dir1/dir2/dir3/file2
| grep -v somestring | grep -v someotherstring ...

so I get a message about the usage of diff, then it tries to execute
file2 as if it were a shell script, then it complains about an
unexpected | at the beginning of a command.

I do not put any \n's or anything like that in the string. If I build
that string with scalars into another scalar and I x that scalar in the
perl debugger, it shows that string as 3 lines, broken up exactly in
the way that causes the unix command processor to complain (as shown
above). I looked for a system variable that might control that
behavior, but couldn't find one.

I get the same results if I use backticks or the system function call.

Help?

Gerald

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-05-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I'm trying to write a script that will do (UNIX) diffs on a set of
> files. I also want to pipe the results to grep -v to eliminate the
> trivial differences. The command gets quite long because of that and
> also because I use the full path name for the files. So the command
> looks like this:
> `diff /dir/dir1/dir2/dir3/file1 /dir/dir1/dir2/dir3/file2 | grep -v
> somestring | grep -v someotherstring ... >
> /dir/dir1/dir2/dir4/file.diff`


Have you considered using Text:iff and grep() instead of shelling all
this out to external processes?

> Somehow that string is wrapped so that the UNIX command processor sees:
>
> diff /dir/dir1/dir2/dir3/file1
> /dir/dir1/dir2/dir3/file2
> | grep -v somestring | grep -v someotherstring ...
>
> so I get a message about the usage of diff, then it tries to execute
> file2 as if it were a shell script, then it complains about an
> unexpected | at the beginning of a command.
>
> I do not put any \n's or anything like that in the string. If I build
> that string with scalars into another scalar and I x that scalar in the
> perl debugger, it shows that string as 3 lines, broken up exactly in
> the way that causes the unix command processor to complain (as shown
> above). I looked for a system variable that might control that
> behavior, but couldn't find one.
>
> I get the same results if I use backticks or the system function call.
>
> Help?


Uhm. Maybe you have an error on line 54, near "fctn1()".

Seriously, though, how can we help you see what's wrong with your code
if we can't see your code?

Please post a short-but-complete script that demonstrates the error
you're seeing. That is, a short script in which you assign scalar
variables to strings without newlines, and print them out to see
newlines magically appear. Then we can help you see what went wrong.

Paul Lalli

 
Reply With Quote
 
 
 
 
gbostock@excite.com
Guest
Posts: n/a
 
      08-05-2005

Paul Lalli wrote:
> (E-Mail Removed) wrote:
> > I'm trying to write a script that will do (UNIX) diffs on a set of
> > files. I also want to pipe the results to grep -v to eliminate the
> > trivial differences. The command gets quite long because of that and
> > also because I use the full path name for the files. So the command
> > looks like this:
> > `diff /dir/dir1/dir2/dir3/file1 /dir/dir1/dir2/dir3/file2 | grep -v
> > somestring | grep -v someotherstring ... >
> > /dir/dir1/dir2/dir4/file.diff`

>
> Have you considered using Text:iff and grep() instead of shelling all
> this out to external processes?


No I hadn't considered that because I was unfamiliar with Text:iff. A
search at http://perldoc.perl.org/index.html for Text:iff didn't
return any results either.

The result I wanted was "external" so why wouldn't I shell it out?

>
> > Somehow that string is wrapped so that the UNIX command processor sees:
> >
> > diff /dir/dir1/dir2/dir3/file1
> > /dir/dir1/dir2/dir3/file2
> > | grep -v somestring | grep -v someotherstring ...
> >
> > so I get a message about the usage of diff, then it tries to execute
> > file2 as if it were a shell script, then it complains about an
> > unexpected | at the beginning of a command.
> >
> > I do not put any \n's or anything like that in the string. If I build
> > that string with scalars into another scalar and I x that scalar in the
> > perl debugger, it shows that string as 3 lines, broken up exactly in
> > the way that causes the unix command processor to complain (as shown
> > above). I looked for a system variable that might control that
> > behavior, but couldn't find one.
> >
> > I get the same results if I use backticks or the system function call.
> >
> > Help?

>
> Uhm. Maybe you have an error on line 54, near "fctn1()".
>
> Seriously, though, how can we help you see what's wrong with your code
> if we can't see your code?


I can't show you the exact code because it is proprietary.

>
> Please post a short-but-complete script that demonstrates the error
> you're seeing. That is, a short script in which you assign scalar
> variables to strings without newlines, and print them out to see
> newlines magically appear. Then we can help you see what went wrong.


I tried to create a dummy program that would reproduce the problem, but
I failed in the attempt. However it shed some light on the solution
which I found. The problem is too embarassing to enumerate here.

Thanks anyway,

Gerald

>
> Paul Lalli


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-05-2005
(E-Mail Removed) wrote:
> Paul Lalli wrote:
> > Have you considered using Text:iff and grep() instead of shelling all
> > this out to external processes?

>
> No I hadn't considered that because I was unfamiliar with Text:iff. A
> search at http://perldoc.perl.org/index.html for Text:iff didn't
> return any results either.


http://search.cpan.org/~rbs/Text-Dif...b/Text/Diff.pm

CPAN is the place you go to find "has anyone else already done this".

> The result I wanted was "external" so why wouldn't I shell it out?


I fail to see your line of reasoning. You have text files. You want
to perform operations on them. You're writing a Perl script to do
this. What is the logic in writing a Perl script that calls shell
commands, as opposed to just doing it in Perl itself?

> > Seriously, though, how can we help you see what's wrong with your code
> > if we can't see your code?

>
> I can't show you the exact code because it is proprietary.


I did not ask you to show us the exact code. See below.

> > Please post a short-but-complete script that demonstrates the error
> > you're seeing. That is, a short script in which you assign scalar
> > variables to strings without newlines, and print them out to see
> > newlines magically appear. Then we can help you see what went wrong.


That is not the same as asking you to show us your proprietary code.

> I tried to create a dummy program that would reproduce the problem, but
> I failed in the attempt. However it shed some light on the solution
> which I found. The problem is too embarassing to enumerate here.


That is *exactly* the point of asking you to create a
short-but-complete script - it almost always leads to the solution.
This is why the Posting Guidelines ask that you do this.

Paul Lalli

 
Reply With Quote
 
Dave Weaver
Guest
Posts: n/a
 
      08-08-2005
On 5 Aug 2005 07:44:41 -0700, (E-Mail Removed) <(E-Mail Removed)> wrote:
> I'm trying to write a script that will do (UNIX) diffs on a set of
> files. I also want to pipe the results to grep -v to eliminate the
> trivial differences. The command gets quite long because of that and
> also because I use the full path name for the files. So the command
> looks like this:
> `diff /dir/dir1/dir2/dir3/file1 /dir/dir1/dir2/dir3/file2 | grep -v
> somestring | grep -v someotherstring ... >
> /dir/dir1/dir2/dir4/file.diff`
>
> Somehow that string is wrapped so that the UNIX command processor sees:
>
> diff /dir/dir1/dir2/dir3/file1
> /dir/dir1/dir2/dir3/file2
> | grep -v somestring | grep -v someotherstring ...
>


You fail to provide enough information to determine the actual
problem, but my spidey sense tells me that your filenames contain a
"\n" at the end.

If you are building up this command from a series of parts, check
*exactly* what each part contains, e.g.
print "[$filename]\n";

If you see:
[/dir/dir1/dir2/dir3/file1
]

then you have a spurious "\n"

Otherwise, follow the posting guidelines for this group by posting a
short but complete program that will demonstrate the problem.
 
Reply With Quote
 
Big and Blue
Guest
Posts: n/a
 
      08-10-2005
(E-Mail Removed) wrote:
>
> Somehow that string is wrapped so that the UNIX command processor sees:
>
> diff /dir/dir1/dir2/dir3/file1
> /dir/dir1/dir2/dir3/file2
> | grep -v somestring | grep -v someotherstring ...


Are you getting the file names by reading from a file?

Have you forgotten to chomp()?

Why not post the actual code so we don't have to guess?


--
Just because I've written it doesn't mean that
either you or I have to believe it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To wrap or not to wrap? Aaron Fude Java 12 05-10-2008 06:33 PM
Odd behavior with odd code Michael Speer C Programming 33 02-18-2007 07:31 AM
Wrap computer components in bubble wrap? Ickshka Computer Support 7 05-05-2006 05:54 PM
Text::Wrap::wrap difference Art Werschulz Perl Misc 1 09-25-2003 06:15 PM
Text::Wrap::wrap difference Art Werschulz Perl Misc 0 09-22-2003 02:36 PM



Advertisments