Вниз
Скачать: CL | DM;

Вопрос по Перлу   Найти похожие ветки 

 
anod ©   (2001-12-12 19:42) [0]

Помогите,
как добавлять текст в начало файла.


 
Дмитрий ©   (2001-12-13 12:43) [1]

open(<IN>, "a.txt");
my @in = (<IN>);
my @ar = (
"First row",
"Second row"
);
my $str = "Third row";
unshift(@in, $str);
unshift(@in, @ar); #unshift(@in, $str, @ar);
open(<IN>, ">a.txt");
print IN @in;
close(IN);


 
anod ©   (2001-12-13 19:59) [2]

2 Дмитрий
Спасибо, а что такое unshift


 
Kapusto ©   (2001-12-14 09:36) [3]

shift наоборот :)

unshift ARRAY,LIST
Does the opposite of a shift. Or the opposite of a push, depending on how you look at it. Prepends list to the front of the array, and returns the new number of elements in the array.

unshift(ARGV, "-e") unless $ARGV[0] =~ /^-/;

Note the LIST is prepended whole, not one element at a time, so the prepended elements stay in the same order. Use reverse to do the reverse.


btw, должно быть
open(IN, "a.txt");



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.007 c
14-8980
MJH
2001-12-11 15:27
2002.02.04
http://mjh.nm.ru


4-9029
irq
2001-12-04 17:49
2002.02.04
Процессы


1-8882
Лана Розанова
2002-01-16 15:13
2002.02.04
Chart и др.


3-8753
sos
2002-01-04 16:53
2002.02.04
Компонента для работы с файлами типа *.btr


1-8863
twinc
2002-01-15 16:31
2002.02.04
ListView Report




   Наверх