Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 27th, 2000, 06:47 PM
wazza wazza is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Brisbane,Q,Au
Posts: 16 wazza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello Everyone,

I have a problem. What i need to do is have an ID number assigned to each order.

$orderno|$another field|$another field|$another field|

For each one i need the number to go up by 1.

Any ideas how this is done. The simpler the better

Thanks guys,
Wazza

Reply With Quote
  #2  
Old August 27th, 2000, 07:38 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
This depends whether you're going to be deleting orders out of that file at some point or whether the file will always have all the consecutive orders numbered from (0,1)?

If you're not going to be deleting, then you just need to read the whole file into an array, determine the index of the last item in the array using $#array and either add 1 to it if you're numbering from 1 or just use that value if your order numbers run from zero.

If you're going to allow deleting out of this file at some point, you need to open the file, read it all into an array, take the last row, extract the order number with a regexp, then add 1 to that.

Something like:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
open FILE, "yourfile.dat"; # open file to read
@data = <FILE>; # whack it all in an array
$lastrow = $data[$#data]; # get the last line
$lastrow =~ s/|.*//g; # chop everything after the first | character
$newindex = $lastrow + 1; # this is our new index number
...
[/code]


Reply With Quote
  #3  
Old August 27th, 2000, 08:08 PM
wazza wazza is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Brisbane,Q,Au
Posts: 16 wazza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok heres what i tried. Keeps printing the same $orderno though

Any ideas?

open(ORDERS, ">>$orders_db") or die "Can't find $orders_db: $!n";
@data = <ORDERS>; # whack it all in an array
$lastrow = $data[$#data]; # get the last line
$lastrow =~ s/|.*//g; # chop everything after the first | character
$orderno = $lastrow + 1; # this is our new index number
print ORDERS "$orderno|$contactname|$contactemail|$company|$title|$description|$category|$emailcategory|$password| $url|$recip|$signupurl|$daten";
close ORDERS;

Thanks Again,
Wazza

Reply With Quote
  #4  
Old August 28th, 2000, 04:01 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
#############################################
#!/usr/local/bin/perl

$num_file = "/path/to/num.txt";
$orders_db = "/path/to/orders.txt";

&check_url;
&get_date;
&parse_form;
&check_required;
&get_variable;
&check_email_host;
&check_ban_host;
&user_existence;
&duplicate_email;
&generate_code;
&get_number;
&write_to_log;
&sendmail;
&increment_num;
&display_output;

sub get_number {
open(NUMBER,"$num_file");
$num = <NUMBER>;
close(NUMBER);
$num++;
}

sub increment_num {
open(NUM,">$num_file");
flock (NUM, 2);
print NUM "$num";
close(NUM);
}
#############################################

The two subroutines provided above are what you asked for. Others are just to give you some idea what order the two should be placed.

num.txt should have "0" initially. No newline, the file pointer should be on the first line, not the second line.


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > bumping a conuter/ID number


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway