Fwd: Splitting Comma delimited list
From: James Edward Gray II (james_at_grayproductions.net)
Date: 12/29/03
- Next message: James Edward Gray II: "Re: Splitting Comma delimited list"
- Previous message: Colin Johnstone: "Re: Splitting Comma delimited list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: Perl List <beginners@perl.org> Date: Mon, 29 Dec 2003 15:42:57 -0600
(redirected to list by James)
Begin forwarded message:
> From: "Stout, Joel R" <Stout.Joel@Menloworldwide.com>
> Date: December 29, 2003 3:37:37 PM CST
> To: "'James Edward Gray II'" <james@grayproductions.net>
> Subject: RE: Splitting Comma delimited list
>
> Not sure if this helps but there are more xml "baddies" to take care
> of....
>
>
> sub xc {
> #returns text free of XML baddies - xc = xml clean
> my $data = $_[0];
> $data =~ s/&/&/g;
> $data =~ s/</</g;
> $data =~ s/>/>/g;
> $data =~ s/'/'/g;
> $data =~ s/"/"/g;
> return $data;
> }
>
> -----Original Message-----
> From: James Edward Gray II [mailto:james@grayproductions.net]
> Sent: Monday, December 29, 2003 1:27 PM
> To: Colin Johnstone
> Cc: beginners@perl.org
> Subject: Re: Splitting Comma delimited list
>
>
> On Dec 29, 2003, at 3:12 PM, Colin Johnstone wrote:
>
>> Hello everyone,
>>
>> I use the following to split a comma delimited list and get varying
>> results and I don't understand why.
>
> Running your code on your data, I get the expected results (43).
>
>> my count of the elements in the splitdata array returns 43 but the
>> select
>> list when displayed in our Content management system only has
>> approximately 23 items. Some items are compltely ignored. The comma
>> delimited txt file is below.
>
> Could this be a browser issue? Is the XHTML still correct?
>
>> About You,BCS Employee,Sales Recognition Events
>> Framework,BPFJ+,Building
>> Wealth,Community Program,Compensation,Employment
>> Confirmations,Employee
>> Development,Employee Services,Executive Development,Expense
>> Reimbursement,Financial Benefits,Flexibility,Global Pulse
>> Survey,Health
>> Benefits,Hiring,HR Assist,IDP Tool,Insurance,Manager
>> Services,Management
>> Development,Mobility,New Hire Information,Other,PaylinkPlus,Payroll
>> Services,PBC Tool - Urgent,PBC Tool - Normal,Peace of Mind
>> Benefits,Personnel Records,Promotions,Reporting,Reporting - Data
>> Quality &
>> Integrity,Site Utilities,Single Cycle Salary Review,Transition
>> Employees,Transactional,Well Being,When Life Changes,Workforce
>> Diversity,Workplace Practices,Your Career
>>
>>
>>
>> #!/usr/bin/perl
>
> # I strongly recommend...
>
> use strict;
> use warnings;
>
>> my $fileToOpen = shift;
>>
>> # $string = qq[<option value="$fileToOpen" label="$fileToOpen"/>];
>>
>> open( FILEHANDLE, $fileToOpen ) or die ("Could not open file
>> $fileToOpen");
>
> # You'll stay sane longer if you think up file handle names better than
> FILEHANDLE
>
>> while( my $line = <FILEHANDLE> ){
>> chomp $line;
>> $inFile .= $line;
>> }
>
> # you can replace the above loop with a single read
>
> undef $/; # enter slurp mode
> my $inFile = <FILEHANDLE>;
>
>> close(FILEHANDLE);
>>
>> my @splitData = split( /\,/, $inFile );
>>
>> $numElements = scalar(@splitData);
>> $optionHTML = qq[<option label="$numElements:" />];
>>
>> foreach $subject(@splitData){
>>
>> $subject =~ s/&/&/g;
>> $subject =~ s/\"/"/g;
>> $optionHTML .= qq[<option label="$subject" />];
>>
>> }
>>
>> # produce output
>> print <<EOF;
>> <?xml version="1.0" encoding='UTF-8'?>
>> <substitution>
>> $optionHTML
>> </substitution>
>> EOF
>> #
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
- Next message: James Edward Gray II: "Re: Splitting Comma delimited list"
- Previous message: Colin Johnstone: "Re: Splitting Comma delimited list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|