Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Update multiple lines in a flat file from array

Reply
Thread Tools

Update multiple lines in a flat file from array

 
 
blnukem
Guest
Posts: n/a
 
      09-04-2004
Hi All

I looking for a simple way to update multiple lines in a flat file from
incoming array with multiple values the file structure goes like this:
Part-number | Name | Quantity

The file looks like this:

123456|headlamp|6
123457|camshaft|3
123458|tire|8
123459|wipperblades|10

The updated incoming values look like this
Part-number | NEW Quantity

123457 4
123459 8

So what I need it to do is update the flat file so it will look like this:

123456|headlamp|6
123457|camshaft|4
123458|tire|8
123459|wipperblades|8

I cant seem to make it work without getting multiple duplicate entry's

Thanks in advance
Blnukem


 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-04-2004
blnukem wrote:
> I looking for a simple way to update multiple lines in a flat file from
> incoming array with multiple values the file structure goes like this:
> Part-number | Name | Quantity
>
> The file looks like this:
>
> 123456|headlamp|6
> 123457|camshaft|3
> 123458|tire|8
> 123459|wipperblades|10
>
> The updated incoming values look like this
> Part-number | NEW Quantity
>
> 123457 4
> 123459 8


You said the new values are from "incoming array". The above doesn't
look anything like a Perl array. Whenever possible, speak Perl, not
English. Show us exactly from where and how your data is arriving.

> So what I need it to do is update the flat file so it will look like this:
>
> 123456|headlamp|6
> 123457|camshaft|4
> 123458|tire|8
> 123459|wipperblades|8
>
> I cant seem to make it work without getting multiple duplicate entry's


What exactly have you tried? Post your attempt, and we can help you see
where you went wrong.

Paul Lalli
 
Reply With Quote
 
 
 
 
blnukem
Guest
Posts: n/a
 
      09-05-2004
incoming array:

foreach $Pair (@Pairs) {
($UniqeID, $Quantity) = split(/=/, $Pair);
}



"Paul Lalli" <> wrote in message
news:chcanf$mjt$...
> blnukem wrote:
> > I looking for a simple way to update multiple lines in a flat file from
> > incoming array with multiple values the file structure goes like this:
> > Part-number | Name | Quantity
> >
> > The file looks like this:
> >
> > 123456|headlamp|6
> > 123457|camshaft|3
> > 123458|tire|8
> > 123459|wipperblades|10
> >
> > The updated incoming values look like this
> > Part-number | NEW Quantity
> >
> > 123457 4
> > 123459 8

>
> You said the new values are from "incoming array". The above doesn't
> look anything like a Perl array. Whenever possible, speak Perl, not
> English. Show us exactly from where and how your data is arriving.
>
> > So what I need it to do is update the flat file so it will look like

this:
> >
> > 123456|headlamp|6
> > 123457|camshaft|4
> > 123458|tire|8
> > 123459|wipperblades|8
> >
> > I cant seem to make it work without getting multiple duplicate entry's

>
> What exactly have you tried? Post your attempt, and we can help you see
> where you went wrong.
>
> Paul Lalli



 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-05-2004
[top posting rearranged as it should be]

blnukem wrote:
> "Paul Lalli" <> wrote
>>blnukem wrote:
>>
>>>I looking for a simple way to update multiple lines in a flat file from
>>>incoming array with multiple values the file structure goes like this:
>>>Part-number | Name | Quantity
>>>
>>>The file looks like this:
>>>
>>>123456|headlamp|6
>>>123457|camshaft|3
>>>123458|tire|8
>>>123459|wipperblades|10
>>>
>>>The updated incoming values look like this
>>>Part-number | NEW Quantity
>>>
>>>123457 4
>>>123459 8

>>
>>You said the new values are from "incoming array". The above doesn't
>>look anything like a Perl array. Whenever possible, speak Perl, not
>>English. Show us exactly from where and how your data is arriving.
>>

> incoming array:
>
> foreach $Pair (@Pairs) {
> ($UniqeID, $Quantity) = split(/=/, $Pair);
> }


>>>So what I need it to do is update the flat file so it will look like
>>>this:

>
>>>123456|headlamp|6
>>>123457|camshaft|4
>>>123458|tire|8
>>>123459|wipperblades|8
>>>
>>>I cant seem to make it work without getting multiple duplicate entry's

>>
>>What exactly have you tried? Post your attempt, and we can help you see
>>where you went wrong.


First, please don't top post. That means please post your reply below
what you are replying to.

Second, you haven't replied to the second part of my post. Please post
the code that you claim isn't working for you. We can't help you debug
your program if we can't see your code.

Paul Lalli
 
Reply With Quote
 
dan baker
Guest
Posts: n/a
 
      09-05-2004
"blnukem" <> wrote in message news:<Y2i_c.5572$ et>...
> Hi All
>
> I looking for a simple way to update multiple lines in a flat file from
> incoming array with multiple values the file structure goes like this:
> Part-number | Name | Quantity
>
> The file looks like this:
>
> 123456|headlamp|6
> -----------------------------------------


this looks like a pretty good candidate to use a tie()ed hash DBfile
rather than a flat text file read in and out.... Be a lot faster and
use less memory probably.

If you insist on a flat text file, and its not *huge* I guess you
could read it all into a hash in memory, do your thing, and then write
it all back out (overwriting the old file).

d
 
Reply With Quote
 
Eric Bohlman
Guest
Posts: n/a
 
      09-05-2004
(dan baker) wrote in
news: om:

> "blnukem" <> wrote in message
> news:<Y2i_c.5572$ et>...
>> Hi All
>>
>> I looking for a simple way to update multiple lines in a flat file
>> from incoming array with multiple values the file structure goes like
>> this: Part-number | Name | Quantity
>>
>> The file looks like this:
>>
>> 123456|headlamp|6
>> -----------------------------------------

>
> this looks like a pretty good candidate to use a tie()ed hash DBfile
> rather than a flat text file read in and out.... Be a lot faster and
> use less memory probably.
>
> If you insist on a flat text file, and its not *huge* I guess you
> could read it all into a hash in memory, do your thing, and then write
> it all back out (overwriting the old file).


It also looks like a good candidate for DBD::CSV, which wouldn't require
any changes to the file format and which has the insert/delete/select
functionality already written. But if that's overkill, then Tie::File
(which is included with the standard Perl distribution) would probably be
helpful.
 
Reply With Quote
 
blnukem
Guest
Posts: n/a
 
      09-06-2004

"Eric Bohlman" <> wrote in message
news:Xns955BAE75BB06Febohlmanomsdevcom@130.133.1.4 ...
> (dan baker) wrote in
> news: om:
>
> > "blnukem" <> wrote in message
> > news:<Y2i_c.5572$ et>...
> >> Hi All
> >>
> >> I looking for a simple way to update multiple lines in a flat file
> >> from incoming array with multiple values the file structure goes like
> >> this: Part-number | Name | Quantity
> >>
> >> The file looks like this:
> >>
> >> 123456|headlamp|6
> >> -----------------------------------------

> >
> > this looks like a pretty good candidate to use a tie()ed hash DBfile
> > rather than a flat text file read in and out.... Be a lot faster and
> > use less memory probably.
> >
> > If you insist on a flat text file, and its not *huge* I guess you
> > could read it all into a hash in memory, do your thing, and then write
> > it all back out (overwriting the old file).

>
> It also looks like a good candidate for DBD::CSV, which wouldn't require
> any changes to the file format and which has the insert/delete/select
> functionality already written. But if that's overkill, then Tie::File
> (which is included with the standard Perl distribution) would probably be
> helpful.



I got it working.


 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      09-06-2004
blnukem wrote:

> incoming array:
>
> foreach $Pair (@Pairs) {
> ($UniqeID, $Quantity) = split(/=/, $Pair);
> }


Equal sign? Your original post did not mention anything about
"=" as part of the data. Now you've got us all confused.
Please try again, showing us actual code and actual input data.

Your "updated input values" belong in a hash, not an array.
Once you've got the hash set up, you can then process the
flat file a line at a time.
-Joe
 
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
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
difference of POD struct array and flat array Peter Steiner C++ 2 11-03-2005 01:12 PM
java with ISAM , flat-file database with multiple keys Mohammad S Khan Java 3 08-31-2004 12:59 PM
Flat file database that supports mulitiple lines, embedded commas, etc. Darrell L. Schmitt Perl Misc 1 08-29-2004 03:56 AM
Re: how to read 10 lines from a 200 lines file and write to a new file?? Joe Wright C Programming 0 07-27-2003 08:50 PM



Advertisments