Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl join on a non printable variable character ?

Reply
Thread Tools

perl join on a non printable variable character ?

 
 
Jack
Guest
Posts: n/a
 
      10-04-2007
Hi I am trying to join on decimal 28, or \034 the non printable field
delimiter. I cant get this to work.. any help would be great ..

assume $delimiter is passed in as \034

works:
@temparray = split(/$delimiter/, $_);
@temparray = split(/\034/, $_);
print OUTFILE1 join("\034",$rowcounter,$_)."\n";

this doesnt work :
print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
print OUTFILE1 join("\$delimiter",$rowcounter,$_)."\n";
print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";
print OUTFILE1 join($$delimiter,$rowcounter,$_)."\n";
or any variation of above ...

 
Reply With Quote
 
 
 
 
Mintcake
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 9:54 pm, Jack <(E-Mail Removed)> wrote:
> Hi I am trying to join on decimal 28, or \034 the non printable field
> delimiter. I cant get this to work.. any help would be great ..
>
> assume $delimiter is passed in as \034
>
> works:
> @temparray = split(/$delimiter/, $_);
> @temparray = split(/\034/, $_);
> print OUTFILE1 join("\034",$rowcounter,$_)."\n";
>
> this doesnt work :
> print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
> print OUTFILE1 join("\$delimiter",$rowcounter,$_)."\n";
> print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";
> print OUTFILE1 join($$delimiter,$rowcounter,$_)."\n";
> or any variation of above ...


So, in the bit that allegedly works, the value of $delimiter (passed
in but we don't see how) is totally ignored. I'd like to see the sub
call and sub declaration.


 
Reply With Quote
 
 
 
 
Jack
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 8:06 am, Mintcake <(E-Mail Removed)> wrote:
> On Oct 4, 9:54 pm, Jack <(E-Mail Removed)> wrote:
>
>
>
>
>
> > Hi I am trying to join on decimal 28, or \034 the non printable field
> > delimiter. I cant get this to work.. any help would be great ..

>
> > assume $delimiter is passed in as \034

>
> > works:
> > @temparray = split(/$delimiter/, $_);
> > @temparray = split(/\034/, $_);
> > print OUTFILE1 join("\034",$rowcounter,$_)."\n";

>
> > this doesnt work :
> > print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
> > print OUTFILE1 join("\$delimiter",$rowcounter,$_)."\n";
> > print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";
> > print OUTFILE1 join($$delimiter,$rowcounter,$_)."\n";
> > or any variation of above ...

>
> So, in the bit that allegedly works, the value of $delimiter (passed
> in but we don't see how) is totally ignored. I'd like to see the sub
> call and sub declaration.- Hide quoted text -
>
> - Show quoted text -


Hey does anyone know how do the join on the non printable /034 ?
Thanks in advance

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      10-04-2007
Jack wrote:
> Hi I am trying to join on decimal 28, or \034 the non printable field
> delimiter. I cant get this to work.. any help would be great ..
>
> assume $delimiter is passed in as \034


Do you really mean \034? \034 is a reference to a literal number.

$ perl -MData:umper -le'$x = \034; print Dumper $x'
$VAR1 = \28;

"\034" is a single character with an ord() value of 28 (034 octal.)

$ perl -MData:umper -le'$x = "\034"; print Dumper $x'
$VAR1 = '';


> works:
> @temparray = split(/$delimiter/, $_);
> @temparray = split(/\034/, $_);
> print OUTFILE1 join("\034",$rowcounter,$_)."\n";
>
> this doesnt work :
> print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
> print OUTFILE1 join("\$delimiter",$rowcounter,$_)."\n";
> print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";
> print OUTFILE1 join($$delimiter,$rowcounter,$_)."\n";
> or any variation of above ...


Does this work?

print OUTFILE1 "$rowcounter$delimiter$_\n";



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
Reply With Quote
 
Greg Bacon
Guest
Posts: n/a
 
      10-04-2007
In article <(E-Mail Removed). com>,
Jack <(E-Mail Removed)> wrote:

: Hi I am trying to join on decimal 28, or \034 the non printable field
: delimiter. I cant get this to work.. any help would be great ..
:
: assume $delimiter is passed in as \034
:
: works:
: @temparray = split(/$delimiter/, $_);
: @temparray = split(/\034/, $_);
: print OUTFILE1 join("\034",$rowcounter,$_)."\n";
:
: this doesnt work :
: print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
: print OUTFILE1 join("\$delimiter",$rowcounter,$_)."\n";
: print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";
: print OUTFILE1 join($$delimiter,$rowcounter,$_)."\n";
: or any variation of above ...

Be more specific than "doesn't work." Tell us what you expected
and how the result failed your expectation.

The output below looks sensible:

$ cat try
#! /usr/bin/perl

use warnings;
use strict;

my $rowcounter = '$rowcounter';
$_ = '$_';

open my $od, "|-", "od -c" or die "$0: fork: $!";

my $separator = "\034";
print $od join($separator,$rowcounter,$_)."\n";

$ ./try
0000000 $ r o w c o u n t e r 034 $ _ \n
0000017

$ perl -v

This is perl, v5.8.8 [...]

Greg
--
Government never furthered any enterprise but by the alacrity with which
it got out of its way.
-- Henry David Thoreau
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 4:55 pm, "John W. Krahn" <(E-Mail Removed)> wrote:
> Jack wrote:
> > Hi I am trying to join on decimal 28, or \034 the non printable field
> > delimiter. I cant get this to work.. any help would be great ..

>
> > assume $delimiter is passed in as \034

>
> Do you really mean \034? \034 is a reference to a literal number.


> "\034" is a single character with an ord() value of 28 (034 octal.)


Using PSI::ESP I suspect the OP really meant he's doing
$delimiter='\034' which is a literal backslash character followed by a
literal zero character and so on.

This thread is a perfect example of why the posting guidelines suggest
a _minimal_ but _complete_ script to illustrate what you are talking
about.

 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 3:54 pm, Jack <(E-Mail Removed)> wrote:
> Hi I am trying to join on decimal 28, or \034 the non printable field
> delimiter. I cant get this to work.. any help would be great ..
>
> assume $delimiter is passed in as \034


See responses elsewhere in this thread. Never ask us to assume. Show
us actual code.

> works:
> @temparray = split(/$delimiter/, $_);


> this doesnt work :
> print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";


I suggest you change split(/$delimiter/, $_) to split(/\Q$delimiter/,
$_)

Then neither will work! But they would work if you'd put the right
value in $delimiter in the first place.

Actually, come to think of it, neither would have worked in your
original code if, as you claim, delimiter really contained \034 but
I'm guessing it really contained '\034'. What it _should_ contain is
"\034".

Just to re-iterate (because I think I may have been unclear
elsewhere), the following are all valid Perl but are very different
statements.

$delimiter=\034; # What you appear to claim you did
$delimiter='\034'; # What you probably actually did
$delimiter="\034"; # What you should have done

By saying in English "$delimiter is passed in as \034" you are not
telling us what you've actually done.

You could have saved us all a lot of trouble by consulting the posting
guidelines before you post.

 
Reply With Quote
 
benwbrewster@gmail.com
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 1:46 pm, Sherman Pendley <(E-Mail Removed)> wrote:
> Brian McCauley <(E-Mail Removed)> writes:
> > Just to re-iterate (because I think I may have been unclear
> > elsewhere), the following are all valid Perl but are very different
> > statements.

>
> > $delimiter=\034; # What you appear to claim you did
> > $delimiter='\034'; # What you probably actually did
> > $delimiter="\034"; # What you should have done

>
> On a related note - I'm not convinced that \034 is the correct character
> to use. The OP mentioned using it as a field separator, and my Unicode
> reference lists 034-037 as file, group, record, and unit separators, res-
> pectively.
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net


ok sorry for not being specific - tried suggestions above and none
worked here is code. my fault for not starting with this - command:
perl e:\add_uniquekeyfield.pl e:\tmp\file1.txt e:\tmp\file2.txt \034
if (@ARGV[0] eq undef) {
$filename="no source filename" ;
} else {
$filename=@ARGV[0];
}

if (@ARGV[1] eq undef) {
$outfilename="no dest filename" ;
} else {
$outfilename=@ARGV[1];
}
if (@ARGV[2] eq undef) {
$delimiter="no dest filename" ;
} else {
$delimiter=@ARGV[2];
}
open(OUTFILE1,">$outfilename")|| die 'ERROR : external table not
found :'.$outfilename."\n";
open(SOURCE,$filename) || die 'ERROR : external table not found :'.
$filename."\n";
while (<SOURCE>) {
chomp; #remove the newline from the line
$rowcounter++;
print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
@temparray = split(/$delimiter/, $_); # works for life of me cant
figure out why join doesnt work, shoot me now
# print OUTFILE1 "$rowcounter$delimiter$_\n";
} #end while
close SOURCE;
close OUTFILE1;

 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 1:46 pm, Sherman Pendley <(E-Mail Removed)> wrote:
> Brian McCauley <(E-Mail Removed)> writes:
> > Just to re-iterate (because I think I may have been unclear
> > elsewhere), the following are all valid Perl but are very different
> > statements.

>
> > $delimiter=\034; # What you appear to claim you did
> > $delimiter='\034'; # What you probably actually did
> > $delimiter="\034"; # What you should have done

>
> On a related note - I'm not convinced that \034 is the correct character
> to use. The OP mentioned using it as a field separator, and my Unicode
> reference lists 034-037 as file, group, record, and unit separators, res-
> pectively.
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net


sorry all, tried everything no luck here is the code. output should
be : 1IDTERM or put otherwise-
rowcounter[nonprintabledelimiter]field1[nonprintabledelimiter]field2
which is visible in the text file perl e:\add_uniquekeyfield.pl e:\tmp
\file1.txt e:\tmp\file2.txt \034

if (@ARGV[0] eq undef) {
$filename="no source filename" ;
} else {
$filename=@ARGV[0];
}

if (@ARGV[1] eq undef) {
$outfilename="no dest filename" ;
} else {
$outfilename=@ARGV[1];
}
if (@ARGV[2] eq undef) {
$delimiter="no dest filename" ;
} else {
$delimiter=@ARGV[2];
}

open(OUTFILE1,">$outfilename")|| die 'ERROR : external table not
found :'.$outfilename."\n";
open(SOURCE,$filename) || die 'ERROR : external table not found :'.
$filename."\n";

while (<SOURCE>) {
chomp; #remove the newline from the line
if (length($_) == 1 or length($_) == 0) { next; }; # skip the row
# @temparray = split(/$delimiter/, $_); # works !!
$rowcounter++;
print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n"; # doesnt work
shoot me now !
print OUTFILE1 "$rowcounter$delimiter$_\n"; # no luck !
} #end while
# print $#temparray;

close SOURCE;
close OUTFILE1;
close OUTFILE2;

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      10-05-2007
Jack wrote:
>
> On Oct 4, 1:46 pm, Sherman Pendley <(E-Mail Removed)> wrote:
>>
>> Brian McCauley <(E-Mail Removed)> writes:
>>>
>>> Just to re-iterate (because I think I may have been unclear
>>> elsewhere), the following are all valid Perl but are very different
>>> statements.
>>> $delimiter=\034; # What you appear to claim you did
>>> $delimiter='\034'; # What you probably actually did
>>> $delimiter="\034"; # What you should have done

>>
>> On a related note - I'm not convinced that \034 is the correct character
>> to use. The OP mentioned using it as a field separator, and my Unicode
>> reference lists 034-037 as file, group, record, and unit separators, res-
>> pectively.

>
> sorry all, tried everything no luck here is the code. output should
> be : 1IDTERM or put otherwise-
> rowcounter[nonprintabledelimiter]field1[nonprintabledelimiter]field2
> which is visible in the text file perl e:\add_uniquekeyfield.pl e:\tmp
> \file1.txt e:\tmp\file2.txt \034


You should put these two lines at the beginning of your Perl program to let
perl help you find mistakes:

use warnings;
use strict;


> if (@ARGV[0] eq undef) {


warnings enabled would have told you that using @ARGV[0] is wrong. Also, you
can't use the value of undef in a comparison like that, you want to use the
defined function instead:

if ( defined $ARGV[0] ) {

Or:

if ( not defined $ARGV[0] ) {


> $filename="no source filename" ;
> } else {
> $filename=@ARGV[0];
> }
>
> if (@ARGV[1] eq undef) {
> $outfilename="no dest filename" ;
> } else {
> $outfilename=@ARGV[1];
> }
> if (@ARGV[2] eq undef) {
> $delimiter="no dest filename" ;
> } else {
> $delimiter=@ARGV[2];
> }


You are passing the string '\034' to your program from the command line so
your $delimiter variable will contain the string consisting of the four
characters '\', '0', '3' and '4'.


> open(OUTFILE1,">$outfilename")|| die 'ERROR : external table not
> found :'.$outfilename."\n";
> open(SOURCE,$filename) || die 'ERROR : external table not found :'.
> $filename."\n";


You should include the $! variable in the error message so you know *why* it
failed.


> while (<SOURCE>) {
> chomp; #remove the newline from the line
> if (length($_) == 1 or length($_) == 0) { next; }; # skip the row
> # @temparray = split(/$delimiter/, $_); # works !!


When used in a regular expression the string '\034' is interpolated by the
string interpolater *and* the regular expression engine so it "works".

$ perl -le' $x = q[\034]; $test = qq[ one \034 two \\034 three ]; print for
split /$x/, $test'
one
two \034 three


> $rowcounter++;
> print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n"; # doesnt work
> shoot me now !


When interpolated only by the string interpolater it is just a string.

$ perl -le' $x = q[\034]; print qq[ zero $x one \034 two \\034 three ];'
zero \034 one two \034 three


> print OUTFILE1 "$rowcounter$delimiter$_\n"; # no luck !
> } #end while
> # print $#temparray;
>
> close SOURCE;
> close OUTFILE1;
> close OUTFILE2;




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
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
matching for specific ascii decimal "non-printable character" Jack Perl Misc 2 07-18-2006 11:36 AM
Removing Non-Printable Character Data Matt ASP .Net 0 10-24-2005 02:53 AM
Question about string.printable and non-printable characters Daniel Alexandre Python 2 03-21-2005 12:34 PM
return the printable form of a character Sam Halliday C Programming 8 07-12-2004 08:44 PM
Non-printable characters in PDF files... Murgi Computer Support 0 06-10-2004 08:54 AM



Advertisments