in reply to Spliting a delimited string into variables

you can try something like

use strict; use warnings; use Data::Dumper; my @data = ("371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|D +B PURGE1|", "371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|DB PURGE1|", "371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|DB PURGE1|", "371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|DB PURGE1|", "371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|DB PURGE1|"); print Dumper(@data); foreach my $field (@data){ my ($ticket,$DateAdded,$STime,$ETime,$Pri,$SiteName,$Comments) = s +plit(/\|/,$field); print"$ticket,$DateAdded,$STime,$ETime,$Pri,$SiteName,$Comments\n" +; }

Replies are listed 'Best First'.
Re^2: Spliting a delimited string into variables
by pissflaps (Initiate) on Apr 07, 2011 at 19:35 UTC

    Thank you! This is very close to where I was originally intending to head with the script. I cannot surmise how to access each element to have the variable assigned to it, though.

    When I run this segment, I fail initializing $field within the split. I'm not sure how I got this error because everything is localized in the loop, right? Would I access these variables with $ticket[0], $ticket[1]? I could easily adapt the rest of the script if this is the case.