Current location: Hot Scripts Forums » Programming Languages » Perl » converting double quote strings to single quotes


converting double quote strings to single quotes

Reply
  #1 (permalink)  
Old 12-15-04, 11:48 AM
mike-g2 mike-g2 is offline
New Member
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
converting double quote strings to single quotes

Hi,

I'm trying to process a data file, much of the data includes characters like % or & which when when I load into perl using <DATAIN> gets put into a double quoted string so that when I try to print it out it gets all screwed up.

Is there a way to either (a) read the file in as a single quoted literal string or (b) some how convert the double quoted string into a single once after its been read in?

I realize this may be a simple problem for those in the know, but I've spent 1+ hour looking through my books and on the web and can't find a solution.

Any help on this would be appreciated.

Thanks.

Mike
Reply With Quote
  #2 (permalink)  
Old 12-15-04, 01:27 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Hey Mike,

Can you post a snippet of your code that reads in the file? Perl doesn't do anything special when reading in files so it sounds like it might be the code used to read in the file.

When you say "when I try to print it out it gets all screwed up" is Perl trying to interpret the &'s and %'s as variables?

~Charlie
Reply With Quote
  #3 (permalink)  
Old 12-15-04, 01:57 PM
mike-g2 mike-g2 is offline
New Member
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Charlie,

Thanks for the reply.

I've put the code I'm using at the end along with some of the input file, the error messages, and the output. It's a simple script to convert my bibliography.bib to one with journal names in a standard format.

And when I say it get's all screwed up I mean that when there's a % I get the message

>Invalid conversion in printf: "%M" at ./convert.bib.using.jtitle.pl line 216, <BIBIN> line 1.
and such when ever there's a line with a %

when there's an& I get...
Invalid conversion in printf: "%e" at ./convert.bib.using.jtitle.pl line 216, <BIBIN> line 4806.
and it adds a \ before &

I suspect there's an easy solution if I had more of a clue...

Mike
__________________________________________________ _____________
#define bibliography file with full journal names
my $bibfull = "bibliography.bib";

#define output file for abbreviated names
my $bibabbr = "bibliography.full.bib";


#load $bibfull and $bibabbr
open BIBIN, $bibfull or die "Couldn't open $bibfull file. Exiting...\n";
open BIBOUT, " >$bibabbr";

my $linestart;
my $fulltitle;
my $abbrtitle;
my $temp;

#read through BIBIN file
while (<BIBIN>) { #each line read into $_ variable
#THIS IS SORTA IRRELAVENT TO THE PROBLEM
#test to see if its a title
if (/^\s*journal\s*=\s*(\w*),/) {
$linestart = ' journal = {';
$abbrtitle = $1;
#convert to all lower case
$abbrtitle=~s/(\w+)/\L$1/g;
if($fulltitle = $lctitle_hash{$abbrtitle}){
$linestart .= $fulltitle;
}
else{
#no abbreviation found
print "\nno abbrv. found for $abbrtitle\n";
$abbrtitle=~s/\b(\w)/\U$1/;
$fulltitle= $abbrtitle;
print "Using $fulltitle\n\n";
}
$linestart .= "\},\n";
printf BIBOUT $linestart;
}

#HERE IS WHERE I GET THE PROBLEM
else{
printf BIBOUT $_;
}
}

close BIBIN;
close BIBOUT;


__________________________________________________ ____________________
Debugging output:

DB<1> c
Invalid conversion in printf: "%M" at ./convert.bib.using.jtitle.pl line 216, <BIBIN> line 1.
Use of uninitialized value in printf at ./convert.bib.using.jtitle.pl line 216, <BIBIN> line 408.
Use of uninitialized value in printf at ./convert.bib.using.jtitle.pl line 216, <BIBIN> line 1643.
.
.
.

__________________________________________________ ___________________
Lines in file that are associated with debugging output
1: %Master Bibiligraphy
408: this behavior can be as high as 10-20\% but declines
1643: optical density ratio (%OD), and amino black

strangely, there's a % in line 1641, but it doesn't seem to cause an error...
the line is
1641: volume ratio (%vol) using Melanie II is a better

__________________________________________________ __
Output associated with above errors
1:%Master Bibiligraphy
408: this behavior can be as high as 10-20\0ut declines
1643: optical density ratio (0D), and amino black

and for
1641: volume ratio (l) using Melanie II is a better
Reply With Quote
  #4 (permalink)  
Old 12-16-04, 11:09 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Try changing you printf's to print's and see if that helps.

~Charlie
Reply With Quote
  #5 (permalink)  
Old 12-17-04, 04:17 PM
mike-g2 mike-g2 is offline
New Member
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
**** that was easy! THanks a 10^6!

Mike
Reply With Quote
  #6 (permalink)  
Old 12-18-04, 01:38 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
No worries. Glad that worked for you

~Charlie
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Numbers Converting to Strings? Trevor JavaScript 1 09-27-04 05:44 PM
Single click refreshing with target of _top Deezul ASP 0 09-22-04 06:57 PM
Writeline - double quotes Davidw Windows .NET Programming 0 06-16-04 12:20 PM
Strings with Quotes " " - How? tony_1017 PHP 7 03-24-04 06:43 PM
[Tutorial] Hello World Antitrust PHP 10 10-14-03 01:27 PM


All times are GMT -5. The time now is 03:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.